如何获得编辑框背景的图像?

有帮助吗?

解决方案

的确,这是非常有可能的。以您的形式定义

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top