如何设置ListView的标题栏弹出菜单连同项弹出菜单? [英] How to set popup menu for ListView header bar together with items popup menu?

查看:271
本文介绍了如何设置ListView的标题栏弹出菜单连同项弹出菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 ViewStyle = vsReport 一个ListView和两个弹出菜单:

I have a ListView with ViewStyle = vsReport and two popup menus:


  1. 柱弹出菜单,我想,当用户右键单击标题栏打开

  2. 项弹出菜单后,当用户右键点击下面的项目列表项/子项或空白必须打开。

  1. Column popup menu, which I want to open when user right-clicking the header bar
  2. 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;

这篇关于如何设置ListView的标题栏弹出菜单连同项弹出菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆