CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2005
    Posts
    226

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

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Prevent Paste or Trap Paste into Edit Box

    Thanx for sharing!

    What about the default context menu for textboxes, that allows you to paste ¿

  3. #3
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Prevent Paste or Trap Paste into Edit Box

    Quote Originally Posted by RoyK View Post
    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?

  4. #4
    Join Date
    Mar 2005
    Posts
    226

    Re: Prevent Paste or Trap Paste into Edit Box

    Quote Originally Posted by Shuja Ali View Post
    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.

  5. #5
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Prevent Paste or Trap Paste into Edit Box

    Quote Originally Posted by RoyK View Post
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured