如何设置ListView的标题栏弹出菜单连同项弹出菜单?
我有 ViewStyle = vsReport
一个ListView和两个弹出菜单:
I have a ListView with ViewStyle = vsReport
and two popup menus:
- 柱弹出菜单,我想,当用户右键单击标题栏打开
- 项弹出菜单后,当用户右键点击下面的项目列表项/子项或空白必须打开。
- Column popup menu, which I want to open when user right-clicking the header bar
- Item popup menu, must open when the user right-clicking any list item/subitem or whitespace below items.
什么是显示菜单的最正确的方法是什么?我应该处理哪些事件?
What is the most correct way to show that menus? Which events should I handle?
问题是,当我设置 ListView.PopupMenu
属性后,右键单击ListView的客户矩形的任何一点出现的弹出式菜单。
The problem is when I set ListView.PopupMenu
property, the popup menu appearing after right-clicking any point in ListView's client rectangle.
当我处理 ListView.OnColumnRightClick
情况下,如果只触发单击列标题,不包括标题栏的可用空间(上栏的右边)之后。
When I handle ListView.OnColumnRightClick
event, if fires only after clicking on column header, excluding free space of the header bar (on the right of columns).
事件 LisView.OnMouseUp
后才下面空白的项目右击闪光。
Event LisView.OnMouseUp
fires only after right-clicking on whitespace below items.
您不必使用列表视图的的PopupMenu
属性,设置就可以了,你可以附加处理程序 OnContextPopup
事件,并启动您希望根据位置的任何弹出菜单。例如:
You don't have to use the PopupMenu
property of the listview, leave it unset and you can attach a handler to OnContextPopup
event and launch whatever popup menu you'd like depending on the position. Example:
procedure TForm1.ListViewContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
var
HeaderRect: TRect;
Pos: TPoint;
begin
GetWindowRect(ListView_GetHeader(ListView.Handle), HeaderRect);
Pos := ListView.ClientToScreen(MousePos);
if PtInRect(HeaderRect, Pos) then
PopupMenuColumns.Popup(Pos.X, Pos.Y)
else
PopupMenuItems.Popup(Pos.X, Pos.Y);
end;