Subclass Text & Combo Boxes
to Display PopUp Menus
Right clicking a textbox pops up the standard context menu with the Cut, Copy
and Paste options. Often you need to display your own menu. You can by
calling the PopupMenu command in the textbox's
MouseUp event. However, the standard context menu still appears. You can remove
it with subclassing.
Subclassing lets you process the messages Window's sends to your control
allowing you to customize their behavior by reacting to or ignoring events that
Visual Basic does not normally give you control over. Be forewarned, however,
that subclassing removes much of the stability and robustness built into Visual
Basic.
Download Source Code
For a thorough discussion of subclassing, visit my Sub-Class
Forms to Intercept Windows Messages page. The code in this sample is
just a variation of the concepts used there.
Download the source code and run it. Right click the top textbox and comboboxes
to verify they function as normal.
Right click the bottom textbox and comboboxes to see that they popup my own menu
without displaying the normal context menu.
|
About TheScarms
Sample code version info
|