添加项目到默认的文本框上下文菜单 [英] Add item to the default TextBox context menu
本文介绍了添加项目到默认的文本框上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么办法增加一个额外的项目添加到默认的WinForms文本框的上下文菜单,而无需创建我自己的?
is there any way to add an extra item to the default WinForms TextBox context menu without creating my own?
推荐答案
子类文本框(从中获得)或本机手柄(带的NativeWindow),然后重写窗口过程如下:
Subclass TextBox (derive from it) or native handle (with NativeWindow), and then override window procedure as follows:
protected override void WndProc(ref Message m)
{
if (m.Msg == <your menu id>) { ... return; }
...
if (m.Msg == 0x0093 /*WM_UAHINITMENU*/ || m.Msg == 0x0117 /*WM_INITMENUPOPUP*/ || m.Msg == 0x0116 /*WM_INITMENU*/)
{
IntPtr shortcut = m.Msg == 0x0093 ? Marshal.ReadIntPtr(m.LParam) : m.WParam;
// add <your menu id> to shortcut
...
}
...
base.WndProc(ref m);
}
这篇关于添加项目到默认的文本框上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文