6

我怎样才能有一个编辑框背景的图像?

4

1 回答 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. 如果我有时间,我可能会这样做。(并且,请注意,没有必要从第三方公司购买昂贵的(也许不是那么高质量的)组件包。)

自定义编辑背景

于 2010-12-02T19:23:27.987 回答