使用 SetWindowLong 命令更改树视图方向时,右键单击(弹出菜单)不起作用
当我使用 SetWindowLong 命令更改树视图的方向时,其节点上的弹出菜单不显示。完整代码在这里:
Procedure SetWinControlBiDi(Control: TTreeView);
var
ExStyle: Longint;
begin
ExStyle := GetWindowLong(Control.Handle, GWL_EXSTYLE);
SetWindowLong(Control.Handle, GWL_EXSTYLE, ExStyle or WS_EX_RTLREADING or WS_EX_RIGHT or WS_EX_LAYOUTRTL or WS_EX_NOINHERITLAYOUT );
end;
procedure TMainForm.FormShow(Sender: TObject);
begin
SetWinControlBiDi(TreeView1);
end;
When I use SetWindowLong command to change direction of treeview, popupmenu on its node dose not show. Full Code is here :
Procedure SetWinControlBiDi(Control: TTreeView);
var
ExStyle: Longint;
begin
ExStyle := GetWindowLong(Control.Handle, GWL_EXSTYLE);
SetWindowLong(Control.Handle, GWL_EXSTYLE, ExStyle or WS_EX_RTLREADING or WS_EX_RIGHT or WS_EX_LAYOUTRTL or WS_EX_NOINHERITLAYOUT );
end;
procedure TMainForm.FormShow(Sender: TObject);
begin
SetWinControlBiDi(TreeView1);
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
执行此操作的标准方法是使用 Delphi
BiDiMode
属性。最好这样做,以便 VCL 知道您想要从右到左。您还需要更改弹出菜单上的 BiDiMode 属性。现在,正确的方法是不要更改各个组件的属性。这样做既费力又容易出错。在应用程序初始化的某个位置设置
Application.BiDiMode
,更改将传播到所有组件。例如,您可以在应用程序的 .dpr 文件中进行更改:
您需要确保未在任何 .dfm 文件中修改任何组件的
BiDiMode
或ParentBiDiMode
。如果您只是从 .dfm 文件中删除这些行,那么将允许单个应用程序范围的Application.BiDiMode
设置来控制一切。您设置 GWL_EXSTYLE 的方法有问题。 VCL 控制该设置,如果您确实需要更改它,在
TForm.OnShow
中执行此操作将导致奇怪的错误。有时需要重新创建窗口,当发生这种情况时,设置GWL_EXSTYLE
的代码将不会运行,并且树视图将恢复为从左到右。如果您确实需要修改窗口样式,那么您需要重写组件的TWinControl.CreateParams
。然而,在这种情况下,VCL 直接支持 BiDi,这是最好的解决方案。The standard way to do this is to use the Delphi
BiDiMode
property. It's best to do it this way so that the VCL is aware that you want right-to-left. You need to change theBiDiMode
property on the popup menu too.Now, the correct way to do this is not to change the properties on the individual components. Doing it that way is laborious and very error prone. Set
Application.BiDiMode
somewhere in your application's initialization and the change will propagate through to all your components.For example you can make the change in your application's .dpr file:
You need to make sure that you have not modified any component's
BiDiMode
orParentBiDiMode
in any .dfm file. If you have simply remove those lines from your .dfm file and that will allow the single application wideApplication.BiDiMode
setting to control everything.Your approach of setting
GWL_EXSTYLE
is problematic. The VCL is in control of that setting and if you do need to change it, doing so inTForm.OnShow
will lead to strange bugs. Sometimes windows need to be re-created and when this happens your code to setGWL_EXSTYLE
will not run and your tree view will revert to left-to-right. If you do need to modify the window styles then you need to overrideTWinControl.CreateParams
for the component. However, in this case the VCL has direct support for BiDi and that is the best solution.这是显示 TPopupMenu 的替代解决方案 在本例中
1- 使用
OnMouseDown
事件2- 编写此代码以在单击鼠标右键时显示 TPopupMenu
祝你好运!
This is an alternative solution to show TPopupMenu In this case
1- Use
OnMouseDown
Event2- Write this code to show a TPopupMenu when you click the right mouse button
Good luck !