delphi - 如何在 THintWindow 内创建 TButton 或其他控件?

标签 delphi hint

我正在尝试创建一个 THintWindow 并在其上放置一个 TButton 或 TFrame 。这是我的代码:

TForm1 = class(TForm)
  Button1: TButton;
  Button2: TButton;
  procedure FormCreate(Sender: TObject);
  procedure Button1Click(Sender: TObject);
  procedure Button2Click(Sender: TObject);
private
  HintWindow: THintWindow;
public
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  HintWindow := THintWindow.Create(Self);
  HintWindow.Color := clInfoBk;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  P: TPoint;
  R: TRect;
  Control: TControl;
begin
  Control := Button1;
  P := Control.ClientToScreen(Point(0, Control.Height));
  R := Rect(P.X, P.Y, P.x + 100, P.Y + 100);
  with TButton.Create(HintWindow) do
  begin
    Parent := HintWindow;
    Caption := 'My Button';
  end;
  HintWindow.ActivateHint(R, 'My Hint');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  HintWindow.ReleaseHandle;
end;

显示了提示窗口,但我没有看到 TButton。提示窗口内似乎没有子窗口(我用 Spy++ 测试了“第一个子窗口”)。 我还尝试使用新的 CreateParams 对 THintWindow 进行子类化,即:

procedure TMyHintWindow.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.Style := Params.Style or WS_CLIPCHILDREN;
  Params.ExStyle := Params.ExStyle or WS_EX_CONTROLPARENT;
end;

当我在提示窗口上创建一个 TFrame 作为子窗口时,Spy++ 显示提示窗口上有一个子窗口,但我看不到它(即使在我强制它可见之后)。

对此有何反馈?

最佳答案

不要问我为什么,但您可以通过设置 ParentWindow 在旧版本的 Delphi 中实现此功能。至Application.Handle创建THintWindow后立即实例:

HintWindow := THintWindow.Create(Self);
HintWindow.ParentWindow := Application.Handle;

这个答案的灵感来自于现代版本的 Delphi VCL 源代码。

关于delphi - 如何在 THintWindow 内创建 TButton 或其他控件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8166670/

相关文章:

freepascal - 在哪里可以找到循环缓冲区的良好 Delphi 或 Object Pascal 实现

delphi - 简单的 TListView 保存文件和从文件加载(仅保存列字符串值)

魔法对象中返回变量的 PhpStorm/PhpDoc 类型提示

java - Netbeans 没有给出提示

java - 使 editText 提示斜体?

带有输入提示的 Java JTextField

delphi - 颜色 alpha channel 不是完全透明的

sql - Delphi中不同区域设置不同格式的Float

delphi - 如果 TSpeedButton 已经按下,如何提前退出()?

php - 网比 "Variable $out seems to be uninitialized"