如何使用 MainMenu 在状态栏上显示与菜单项相关的文本?
常见的 UI 模式是在状态栏中显示与当前所选菜单项相关的文本。
过去,我通过创建一个扩展程序提供程序在 winforms 中实现了这一点,该扩展程序提供程序添加一个字符串属性,其中包含要在状态栏中显示的每个菜单项的自定义文本。 这是通过向 MenuStrips MouseEnter 和 MouseLeave 事件添加事件处理程序来显示和删除文本来实现的。
我遇到的问题是我现在使用 MainMenu 控件而不是 MenuStrip,并且由于它不是从 Control 派生的,因此没有 MouseEnter 和 MouseLeave 事件。
MainMenu 有一个 Click 事件,这意味着我可以在状态栏上显示文本,但据我所知,无法检测鼠标何时离开菜单项并从状态栏中删除文本。
我的问题是如何使用 MainMenu 控件实现此 UI 模式?具体来说,我想知道如何检测鼠标何时离开菜单项,以便可以从状态栏中删除文本。
注意:MenuStrip 控件不是一个选项,因为它不使用操作系统的外观和感觉,我正在尝试使我的应用程序尽可能地适应这一点。
A common UI pattern is to display text in the status bar that is related to the currently selected menu item.
In the past I have achieved this in winforms by creating an extender provider that adds a string property with the custom text for each menu item to be displayed in the statusbar.
This was achieved by adding event handlers to the MenuStrips MouseEnter and MouseLeave events to display and remove the text.
The problem I am having is that I am now using a MainMenu control instead of a MenuStrip and since it doesn't derive from Control it doesn't have MouseEnter and MouseLeave events.
The MainMenu has a Click event which means that I can display my text on the statusbar but as far as I can see there is no way to detect when the mouse has left the menu item and remove the text from the statusbar.
My question is how can I implement this UI pattern using the MainMenu control? Specifically I would like to know how to detect when the mouse has left the menu item so that the text can be removed from the statusbar.
Note: The MenuStrip control is not an option as it doesn't use the operating system look and feel and I am trying to make my application fit in with this as much as possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个 MenuItem 都有 选择事件。连接到它并相应地更改您的状态文本。
好吧,至于检测项目的退出,请使用计时器,记住最后输入的
MenuItem
的Rect
,然后当(检查计时器事件)它消失时,取消文本。不漂亮,但可以工作。Each MenuItem has Select event. Connect to it and change your status text accordingly.
Well, as for detecting exiting of the item, use the timer, Remember the
Rect
of the last enteredMenuItem
, then when (check on timer event) it goes out, cancel the text. Isn't pretty, but could work.