Delphi菜单选择
我的问题是如何捕获以某种形式按下了哪个菜单项?举个例子:
我有一个带有按钮的表单。当我按下按钮时,应用程序的菜单将成为焦点,并且子窗体等待选择菜单项。选择一个后,子窗体会显示一条消息,其中包含我按下的菜单项的名称。
谁能告诉我该怎么做?
提前致谢!
My question is how to catch which menu item was pressed in some form? For an example :
I have a form with a button. When I pressed the button the menu of the application will be on focus and the child form wait to choose a menu item. After I choose one the child form show a message with the name of the menu item which I pressed.
Can anyone tell me how to do this?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这样的事情是对您的问题的直接回答:
此事件处理程序应该连接到您希望以这种方式表现的每个菜单项。
您似乎想要对菜单项的执行进行一些集中日志记录或监视。如果您使用操作并将它们与菜单项相关联,那么您可以获得应用程序范围内的通知,表明操作已执行。将
TApplicationEvents
对象拖放到主窗体上并处理其OnActionExecute
事件。像这样:每当您的应用程序中执行任何事件时,都会触发该事件。
Something like this is a direct answer to your question:
This event handler should be connected to each menu item that you wish to behave this way.
It seems that you want some centralised logging or monitoring of the execution of menu items. If you use actions and associate these with your menu items then you can get an application wide notification that an action has been executed. Drop a
TApplicationEvents
object onto your main form and handle itsOnActionExecute
event. Like this:This will fire whenever any event in your app is executed.
示例:
全局变量(TMyForm 中的私有声明):
您的 TButton 处理程序:
您的 TMenuItem 事件处理程序:
example:
global variables (private declaration in TMyForm):
your TButton handler:
your TMenuItem event handler: