如何更改(以及稍后恢复)文本框中的默认上下文菜单
我想更改默认的文本框上下文菜单,所以我创建了自己的菜单,并像这样分配了它们
texbox.ContextMenu = myContextMenu
,但是我不知道如何恢复默认的文本框菜单(在运行时)。仅当我用鼠标右键单击文本框(同时按住 Control 按钮)时,我才需要显示 myContextMenu。在其他情况下,我需要显示默认的文本框上下文菜单。 是否可以 ??
I wanted to change default textbox context menu, so I created my own menu and them I assigned it like that
texbox.ContextMenu = myContextMenu
However I don't know how to restore default textbox menu (in a runtime). I need myContextMenu to show only when I click textbox with right mouse button (while holding Control button). In other cases I need default textbox contextmenu to show.
Is it possible ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下是微软给出的示例:
http://msdn.microsoft.com/en -us/library/ms750420.aspx
郑重声明,以下是使用 WinForms 执行此操作的方法:
HTH!
Here is the example given by Microsoft:
http://msdn.microsoft.com/en-us/library/ms750420.aspx
For the record, here is the way to do this using WinForms:
HTH!
实际上,这比乍看起来更难做到。我相信默认上下文菜单是控件实际模板的一部分。
如果您只想剪切/复制/粘贴,最简单的方法是创建第二个上下文菜单来实现这些选项。如果这样做,您可以使用内置的 ApplicationCommands 来实现 not不仅仅是功能,还要自动本地化这个ContextMenu。
It would actually be more difficult to do than it would first seem. I believe that the default context menu is part of the actual template of the control.
The simplest approach, if you only want Cut/Copy/Paste, is to create a second ContextMenu implementing those options. If you do, you can use the built in ApplicationCommands to implement not only the functionality, but also to automatically localize this ContextMenu.
您可以将 ContextMenu-Property 设置为 null。 OnContextMenuOpening 事件也可以帮助您。
You could just set the ContextMenu-Property to null. Also the OnContextMenuOpening event can help you.