作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 ListView 中有一个弹出菜单,当点击不在任何行上时,我希望将其禁用,我想知道在 ListView 或 PopupMenu 的什么事件上我应该执行此操作。
提前致谢
最佳答案
像这样处理弹出菜单的OnPopup
事件:
procedure TForm1.PopupMenu1Popup(Sender: TObject);
begin
if ListView1.SelCount=0 then begin
Abort;
end;
end;
不要尝试在逻辑中使用鼠标光标,因为可能会从键盘调用弹出菜单。
<小时/>事实证明,您想要根据选择禁用菜单上的某些项目。您应该为此使用操作,然后可以集中控制 UI 属性。操作可以链接到按钮、弹出菜单项、主菜单项等。您不想编写分别启用和禁用所有这些功能的代码 - 操作可以解决这个问题。
为此使用 OnUpdate
事件。
procedure TForm1.Action1Update(Sender: TObject);
begin
Action1.Enabled := ListView1.SelCount>0;
end;
或者有时您希望对许多操作使用相同的 OnUpdate
,您可以在代码中列出以下内容:
procedure TForm1.FileActionsUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled := ListView1.SelCount>0;
end;
关于delphi - delphi中未选择行时禁用listview的弹出菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6789952/
我是一名优秀的程序员,十分优秀!