是否可以获取和修改文本框的标准系统上下文菜单? [英] Is it possible to obtain and modify standard system context menu for textbox?

查看:21
本文介绍了是否可以获取和修改文本框的标准系统上下文菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有文本框的简单 winform 应用程序.
我没有为文本字段分配任何上下文菜单,并且它使用"标准菜单.我希望在文本框的标准上下文菜单中添加一些新项目.但是我无法获取它进行修改,如果更清楚我不知道如何获取HMENU本机对象.
我的文本框的 ContextMenu 属性等于 null 所以我想菜单 appers 在文本框默认的 windProc 路由中.有没有办法获取默认上下文菜单或获取它的副本?

I have a simple winform app with textbox.
I didnt assigned any context menu to text field and "it uses" standard one. I desire to add some new items to textbox's standard context menu. But I cant obtain it for modification, if be more clearly I didnt know how to obtain HMENU native object.
ContextMenu property of my textbox equals null so I suppose that menu appers within textbox defaul windProc routing. It there a way to get the default context menu or get a copy of it?

提前致谢!

推荐答案

根据您使用的任何插件,创建从 TextBox 派生并定义默认"上下文菜单.然后,将解决方案中的所有 TextBox 更改为自定义控件.否则,如果您有一个公共窗口祖先,请设置一些初始化代码,将给定的 ContextMenu 分配给文本框类型的窗体层次结构中的所有控件.您不是插入低级 Windows 挂钩,而是使用框架为您提供的功能来完成相同的目的,并且您的后代不必知道 Windows 如何在消息传递级别处理上下文菜单以更改这种行为.

Depending on any plug-ins you're using, it may be easier, and more understandable, to create a custom control that derives from TextBox and defines a "default" contextual menu. Then, change all TextBoxes in your solution to be your custom control instead. Failing that, if you have a common window ancestor, set up some initialization code that assigns a given ContextMenu to all controls in the form's hierarchy of type TextBox. Instead of plugging in to low-level Windows hooks, you're using what the framework gives you to accomplish the same end, and your posterity doesn't have to know how Windows handles contextual menus at a message-passing level in order to alter this behavior.

这篇关于是否可以获取和修改文本框的标准系统上下文菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆