And*_*and 14

事实上,这是非常可能的.在您的表单中,定义

private
  { Private declarations }
  FBitmap: TBitmap;
  FBrush: HBRUSH;
protected
  procedure WndProc(var Message: TMessage); override;      
Run Code Online (Sandbox Code Playgroud)

并做

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;
Run Code Online (Sandbox Code Playgroud)

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;
Run Code Online (Sandbox Code Playgroud)

当然,你可以将它包装成你自己的组件,比方说TEditEx.如果我有时间,我可能会这样做.(并且,请注意,没有必要从第三方公司购买昂贵的(可能不是那么高质量的)组件包.)

自定义编辑背景

  • 为何选择WM_CTLCOLOREDIT?禁用控件时不会调用它.为什么不WM_ERASEBACKGROUND和WM_PRINTCLIENT? (2认同)