gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 14:43:43 27 4
gpt4 key购买 nike

我正在尝试创建一个 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com