[C# Helper]
Index Books FAQ Contact About Rod
[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[Beginning Software Engineering]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Remove a TextBox control's context menu in C#

[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.

© 2009-2022 Rocky Mountain Computer Consulting, Inc. All rights reserved.