加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-15 04:11:33 所属栏目:大数据 来源:网络整理
导读:如何为Editbox背景提供图像? 解决方法 事实上,这是非常可能的.在您的表单中,定义 private { Private declarations } FBitmap: TBitmap; FBrush: HBRUSH;protected procedure WndProc(var Message: TMessage); override; 并做 procedure TForm1.FormCreate(S
如何为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:UsersAndreas RejbrandPicturesAS20Utv.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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读