Prevent Paste or Trap Paste into Edit Box
Found how to do it:
In the key down event for a text or rich text box:
If (e.Control) And (e.KeyCode = Keys.V) Then e.SuppressKeyPress = True
To prevent pasting for all text boxes on your form, set form KeyPreview to true and add the above code to form key down event.
Re: Prevent Paste or Trap Paste into Edit Box
Thanx for sharing! :thumb:
What about the default context menu for textboxes, that allows you to paste ¿ :)
Re: Prevent Paste or Trap Paste into Edit Box
Quote:
Originally Posted by
RoyK
Found how to do it:
In the key down event for a text or rich text box:
If (e.Control) And (e.KeyCode = Keys.V) Then e.SuppressKeyPress = True
To prevent pasting for all text boxes on your form, set form KeyPreview to true and add the above code to form key down event.
What if you have another control a form that requires a paste operation? How will you handle that?
Re: Prevent Paste or Trap Paste into Edit Box
Quote:
Originally Posted by
Shuja Ali
What if you have another control a form that requires a paste operation? How will you handle that?
I would add a either a menu item with a paste option or command button that allows you to paste.
Re: Prevent Paste or Trap Paste into Edit Box
Quote:
Originally Posted by
RoyK
I would add a either a menu item with a paste option or command button that allows you to paste.
This is just out of curiosity, why would you disable a default behavior of a windows UI? Is there a specific functionality that you are building?