disable paste in a textbox
-
hi id like to prevent people from pasting in my text box what is the best way to trap the keyboard commands and stop the paste menu from poping up on right click?
-
Hello Tyrus, In this case you should use the KeyDown Event.
this.textbox.KeyDown += new KeyEventHandler(CheckKeys); private void CheckKeys(object sender, KeyEventArgs e) { if (e.Control && e.KeyCode == Keys.V) e.Handled = true; }
All the best, Martin -
Hello Tyrus, Maybe for your project it would be helpfull if you use a MYTextBox class which inherits from windowsd Textbox. There you can override the MouseUp Event.
protected override void OnMouseUp(MouseEventArgs e) { if(e.Button != MouseButtons.Right) { base.OnMouseUp (e); } }
Hope it works for you! All the best, Martin -
On the body tag just write the following code. It will disable the right Click in a page. Vipin