How to disable right click and cut/copy and paste options in user controls.


In this article,I will explain how to disable right click and cut/copy and paste options in user controls like text box ,rich text boxes etc in applications.This may be useful while developing security rich applications.

In this article,I have described how to disable right click and cut/copy and paste options in user controls.These may be used in applications which need more security while getting information from the user like password,PIN number etc.This would help us to double check whether the user has given the correct data.

1. The code given below describes how to diable right click option.
The code has to used in textbox mouse down event.



private void textBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
MessageBox.Show("Right click is disabled");
}
}



2.The code given below describes how to disable cut/copy and paste options( Ctrl+X,Ctrl+C and Ctrl+V) through keys.
The code has to be used in textbox keydown event.



private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control == true)
{
MessageBox.Show("Cut/Copy and Paste Options are disabled");
}
}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: