user2033045
user2033045

Reputation:

How to disable the right-click context menu on textboxes in Windows, using C#?

How to disable the right-click context menu on textboxes in Windows, using C#? Here's what I've got, but it has some errors.

private void textBox1_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {   
       textBox1.ContextMenu.Dispose();               
    }                       
}

Upvotes: 14

Views: 16971

Answers (2)

Damith
Damith

Reputation: 63065

try with

textBox1.ShortcutsEnabled =false;

Use the ShortcutsEnabled property to enable or disable the following shortcut key combinations and the control’s shortcut menu:

  • CTRL+Z

  • CTRL+E

  • CTRL+C

  • CTRL+Y

  • CTRL+X

  • CTRL+BACKSPACE

  • CTRL+V

  • CTRL+DELETE

  • CTRL+A

  • SHIFT+DELETE

  • CTRL+L

  • SHIFT+INSERT

  • CTRL+R

Upvotes: 16

7alhashmi
7alhashmi

Reputation: 924

Try to do this:

textBoxt1.ContextMenu = new ContextMenu();

Upvotes: 10

Related Questions