c# - How to detect click from default context menu (ComboBox) -
i have combobox in winforms c# project. when user right clicks combobox bring context menu, selects item (left click) default contextmenustrip, want able capture event. event should handle?
is possible without making own custom contextmenustrip? if have make own, there way use windows default contextmenustrip starting point?
edit: question similar: add item default textbox context menu
but talking adding items default menu. asking capturing events selecting item default context menu. if need make custom contextmenustrip this, fine, please answer way.
sorry, had misunderstood question, have modified answer show how detect click context menu
while searching solution, came across many articles pointed winproc. going down avenue, came across following
since interested in click command, went menu notifications , checked out wm_menucommand message.
you have create user control , change inherit textbox , add following overrides
public partial class textboxusingdefaultcontextmenu : textbox { public textboxusingdefaultcontextmenu() { initializecomponent(); } protected override void wndproc(ref message m) { const int wm_contextmenu = 0x007b; const int wm_menucommand = 0x0126; const int wm_command = 0x0111; switch (m.msg) { case wm_contextmenu: messagebox.show("opening context menu"); break; case wm_menucommand: messagebox.show("wm menu command event fired"); break; case wm_command: messagebox.show("wm command event fired"); break; } base.wndproc(ref m); } protected override void defwndproc(ref message m) { base.defwndproc(ref m); } }
w.r.t code above, can detect "context menu opening" event not yet clicked event. here appreciated others , topic new me.
Comments
Post a Comment