- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
应该很简单,但我看不到。
您可以通过以下方式找到右键单击以显示弹出菜单的组件:
PopupMenu1.PopupComponent
但是如何找到包含依次单击该菜单的 TMenuItem 的弹出菜单呢?
将问题简化为示例:
我有一系列标签,每个标签都有不同的标题,并且有一个分配给每个标签的 PopupMenu 属性的弹出菜单。
当有人右键单击其中一个标签并调出弹出菜单,然后单击 MenuItem1 时,我想编写代码:
procedure TForm1.MenuItem1Click(Sender: TObject);
begin
MsgBox (Format ('The label right-clicked has the caption %', [xxxx.Caption ])) ;
end ;
xxxx 应该是什么?
已实现的答案
感谢两位受访者。我最终得到的是这样的:
procedure TForm1.MenuItem1Click(Sender: TObject);
var
AParentMenu : TMenu ;
AComponent : TComponent ;
ALabel : TLabel ;
begin
AParentMenu := TMenuItem (Sender).GetParentMenu ;
AComponent := TPopupMenu (AParentMenu).PopupComponent ;
ALabel := TLabel (AComponent) ;
MsgBox (Format ('The label right-clicked has the caption %', [ALabel.Caption ])) ;
end ;
它还会询问涉及哪个 TMenuItem,因此为我提供了一段代码,我可以将其放入其他 OnClick 处理程序中,只需进行较少的修改。
最佳答案
我对你的问题有点困惑,但由于你已经排除了其他所有内容,我只能想象你正在寻找 TMenuItem.GetParentMenu
。
关于delphi - 如何找出 TMenuItem 属于哪个 TPopupMenu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6160888/
我使用 Borland C++ Builder 2009,当使用大字体时,MainMenu 和 Popup 中的菜单项彼此靠得太近,文本在顶部和底部甚至被切断,当太大时。 我知道我可以使用 TMenu
我有这样的菜单结构: 1. Option A 1.1 Option B 1.1.1 Option C 1.1.2 Option D 1.2 Option
我想将位图添加到动态创建的 TMenuItem 中。使用此代码它不起作用,我的菜单上没有该图像。怎么了? procedure TForm3.FormCreate(Sender: TObject); v
在我的 Delphi 表单的 OnShow 方法中,我确定打开表单后必须自动打开一个对话框 - 并且我应该能够通过模拟单击菜单项来完成此操作。 但是,调用 menuitem.Click 在主窗体打开之
我试图将 TPopupMenu 作为子组件包含到自定义组件中,如下所示: interface TComp1 = class(TComponent) private FMenu: TPo
在我的一个应用程序中,下拉菜单和弹出菜单共享一些菜单项(动态构建的),所以我想我可以使用此代码将 TMenuItem 实例添加到两个菜单中: MI := TMenuItem.Create(nil);
创建 TMenuItem 运行时时如下所示: mi := TMenuItem.Create([所有者]); 并像这样添加到 TPopupMenu 中: PopupMenu1.Items.Add(mi)
应该很简单,但我看不到。 您可以通过以下方式找到右键单击以显示弹出菜单的组件: PopupMenu1.PopupComponent 但是如何找到包含依次单击该菜单的 TMenuItem 的弹出菜单呢?
我正在使用Delphi XE6和VCL样式。我有主要的应用程序和 dll。我的主应用程序已启用运行时主题,并且我正在使用 vcl 样式文件。我对 DLL 做了非常相似的事情。我启用了运行时主题,并在使
创建自动管理其选中属性的自定义 TMenuItem 的正确方法是什么。请记住,一旦有人会: myHelloItem.OnClick := helloword; 然后行为就丢失了...... 在 Del
我正在使用 C++ Builder 开发应用程序。我想遍历 MainMenu 中的所有 TMenuItems,因为我想更改其中一些的标题。我使用了这段代码: int numAction = Main
我正在开发一个Word插件,不知何故,TAction.ShortCut中定义的快捷方式总是被触发多次,这对我来说很棘手,很难解决,所以我求助于TForm.OnKeyDown事件并清除了所有TActio
我需要为 Delphi 的 TPopupMenu 和 TMenuItem 后代控件编写自定义组件编辑器。 找到 native 编辑器将使我的工作更容易,但在检查文件夹“\source\Property
我该怎么做才能使菜单项的快捷方式不会覆盖本地控件的快捷方式? 想象一下屏幕截图中的这个简单的应用程序。它有一个“撤消”菜单项,并分配有快捷键 CTRL+Z(德语中的 Strg+Z)。当我在备忘录中编辑
我是一名优秀的程序员,十分优秀!