如何为Edit(Delphi)设置背景图像

前端之家收集整理的这篇文章主要介绍了如何为Edit(Delphi)设置背景图像前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何为EditBox背景提供图像?

解决方法

事实上,这是非常可能的.在您的表单中,定义
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.如果我有时间,我可能会这样做. (并且,请注意,没有必要从第三方公司购买昂贵的(可能不是那么高质量的)组件包.)

Custom edit background http://privat.rejbrand.se/editbkg.png

猜你在找的Delphi相关文章