簡體   English   中英

將項添加到默認的TextBox上下文菜單

[英]Add item to the default TextBox context menu

有沒有辦法在沒有自己創建的情況下將額外的項添加到默認的WinForms TextBox上下文菜單中?

子類TextBox(從它派生)或本機句柄(使用NativeWindow),然后覆蓋窗口過程,如下所示:

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);
}

我認為你應該覆蓋WndProc並捕獲文本框接收的消息。

這是可能的,但很復雜。 我建議您使用“現代”ContextMenuStrip類而不是標准ContextMenu來實現自己的菜單。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM