【发布时间】:2020-06-11 01:33:16
【问题描述】:
我正在尝试在运行时创建一个自定义 TToolbar,它浮动在表单上(在与之关联的控件下方)。
我的问题是,在创建时浮动和定位工具栏的过程会产生可怕的闪烁,它最初是在显示器的左上角绘制的,然后才被移动到表单上我想要的位置。
我找不到避免这种情况的方法。有什么办法吗?
procedure TMainForm.Button3Click(Sender: TObject);
var
newToolbar : TToolbar;
newButton : TToolButton;
begin
newToolbar := TToolbar.Create(Self);
newToolbar.Visible := False;
newToolbar.ManualFloat( Rect( 0, 0, newToolbar.Width, newToolbar.Height ));
newToolbar.Parent := Self;
newToolbar.left := 100;
newToolbar.Top := 100;
newToolbar.ShowCaptions := True;
newButton := TToolButton.Create(Self);
newButton.Parent := newToolbar;
newButton.Caption := 'Test';
newToolbar.Visible := True;
end;
参考资料: - Create TToolbutton runtime - toolbutton with action created at runtime - Delphi - Create a custom TToolBar component
【问题讨论】:
-
你为什么要分配 ParentWindow?
-
我还想看到minimal reproducible example。这样我们就可以轻松开始调试了。否则,我们很有可能尝试重新创建它并失败,浪费时间。例如,问题的出现可能只是因为您的程序中做出了其他选择。
-
@DavidHeffernan:该代码应该在任何应用程序中重现该问题
-
“应该”并不能说服我花时间制作应用程序。没关系。也许其他人会给你他们的时间。
-
@DavidHeffernan:我在三个应用程序中测试了它,包括一个完全空白的应用程序。所以它应该在任何应用程序中都可以工作(99% 的确定性),但我不能保证它会,也许我的 Delphi 设置中有一些问题......
标签: delphi