如何设置背景图像编辑(德尔福)

问题描述 投票:6回答:1

我怎么能对编辑框背景图片?

delphi background editbox
1个回答
14
投票

这是非常有可能的,确实如此。在表单,定义

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。如果我有时间了,我可能做到这一点。 (而且,请注意,没有必要购买昂贵的(也许不是高品质的)组件包从第三方公司。)

© www.soinside.com 2019 - 2024. All rights reserved.