5

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?

Thanks in advance!

Anton Semenov
  • 6,227
  • 5
  • 41
  • 69

1 Answers1

1

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.

KeithS
  • 70,210
  • 21
  • 112
  • 164
  • Thank you for answer! The solution provided is pretty good, but I desire to modify system menu because I want have menu dependent on the system. Its not a secret that WinXP and Win7 have different default textbox context menus, so in case of system modification I would not break user expectations about default menu, but of course this is not critical and Im more inclined to make custom menu rather than modify system one. But for now I still have very weak hope that system meny might be modified easily. – Anton Semenov May 16 '11 at 20:32
  • OK, my hope is gone. Im creating custom menu now. Thank again for your advice! – Anton Semenov May 19 '11 at 18:47