delphi - 如何设置编辑的背景图像(Delphi)

标签 delphi background 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

关于delphi - 如何设置编辑的背景图像(Delphi),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4337919/

相关文章:

xml - 保存XML文档会将单引号更改为双引号

html - 我可以只为 div 的背景图像设置不透明度吗?

c# - 如何在 Office 功能区开发的编辑框中隐藏密码文本

c++ - MFC CEdit 控件添加到加速器后不处理按下的按键

delphi - (如何)我可以在断点时导出调用堆栈吗?

delphi - 带有未绑定(bind)列的 Devexpress 网格

android - 每当我在模拟器中打开它时,我的布局都会变得困惑(它是带有 TextView 的背景图像)

android - 更改android中编辑文本框的外观

delphi - 如何创建带有在设计时接受其他控件的子面板的自定义控件?

android - 如何设置一个空的 ListView 的背景图片?