我怎样才能有一个编辑框背景图像?
最佳答案
这确实是很有可能的。在您的表单中定义
private
{ Private declarations }
FBitmap: TBitmap;
FBrush: HBRUSH;
protected
procedure WndProc(var Message: TMessage); override;
然后做
procedure TForm1.FormCreate(Sender: TObject);
begin
FBitmap := TBitmap.Create;
FBitmap.LoadFromFile('C:\Users\Andreas Rejbrand\Pictures\AS20Utv.bmp');
FBrush := 0;
FBrush := CreatePatternBrush(FBitmap.Handle);
end;
和
procedure TForm1.WndProc(var Message: TMessage);
begin
inherited;
case Message.Msg of
WM_CTLCOLOREDIT, WM_CTLCOLORSTATIC:
if (Message.LParam = Edit1.Handle) and (FBrush <> 0) then
begin
SetBkMode(Message.WParam, TRANSPARENT);
Message.Result := FBrush;
end;
end;
end;
当然,您可以将其包装到您自己的组件中,例如TEditEx
。如果我有时间的话,我可能会这样做。 (并且,请注意,无需从第三方公司购买昂贵的(可能不是那么高质量)组件包。)
关于delphi - 如何设置编辑的背景图像(Delphi),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4337919/