Title: Remove a TextBox control's context menu in C#
Normally a TextBox control has a context menu that appears when you right-click it, but what if you don't want that context menu? I mean, really. Am I required to have "Show Unicode control characters" and "Open IME" on every single TextBox?
In case you don't know, "Open IME" toggles the Input Method Editor that lets you enter Chinese, Japanese, Korean, and other non-Latin characters from your keyboard. If you don't use those languages, you don't need it but it's in the context menu anyway.
You can replace a TextBox control's context menu with one of your own by adding a ContextMenuStrip to the form and setting the TextBox control's ContextMenuStrip property equal to to it.
If you want to prevent any context menu from appearing, set the TextBox control's ShortcutsEnabled property to false.
In this example, the top TextBox is normal and displays the default context menu when you right-click it. The second TextBox displays a custom context menu that has Copy, Cut, and Paste commands. The bottom TextBox has ShortcutsEnabled set to false so it doesn't display any context menu.
Download the example to experiment with it and to see additional details.
|