Remove a TextBox control’s context menu in C#

[context menu]

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 Example   Follow me on Twitter   RSS feed   Donate

This entry was posted in controls and tagged , , , , , , , , , , . Bookmark the permalink.

1 Response to Remove a TextBox control’s context menu in C#

  1. JN says:

    Thanks a lot:)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.