Results 1 to 9 of 9

Thread: How to disable Ctrl+V

  1. #1
    Join Date
    Aug 2010
    Posts
    67

    How to disable Ctrl+V

    I have seen many posts on this but I can not get it to work.

    When the user press Ctrl+V, neither KeyDown or KeyPressed events are triggered.

    (I do see the KeyDown event for the Control key being pressed, but never for the V.

    I am trying to prevent the user from adding any text to the txTextControl unless they are within specific TextFields. I am successful with this except oen tester foudn they could press Ctrl+V to paste text even when not within a TextField.

    Thanks
    Bill

  2. #2
    Join Date
    Sep 2004
    Location
    Bremen, Germany
    Posts
    5,929

    Re: How to disable Ctrl+V

    Hi Bill,

    How do you exactly try to intercept CTRL+V in your project?
    Could you please attach a new sample project as ZIP?
    Thanks.
    Regards,
    Gunnar Giffey, TX Text Control
    [Forum Administrator]

  3. #3
    Join Date
    Aug 2010
    Posts
    67

    Re: How to disable Ctrl+V

    OK, I tried to make a test project for you and this worked as I expected it to:

    Code:
    Private Sub TextControl1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextControl1.KeyDown
            If e.KeyCode = Keys.V And e.Control Then
                e.Handled = True
                Beep()
            End If
    End Sub
    It intercepts Ctrl+V and prevents the paste from occurring.

    But in my real app the Key_Down event traps every keystroke -- even every other Ctrl+keystroke -- except Ctrl+V.

    My real project is too large to wrap up and send to you. Do you know of anything that could cause this behavior?
    Last edited by Gunnar Giffey; May 24, 2011 at 09:49:16.

  4. #4
    Join Date
    Sep 2004
    Location
    Bremen, Germany
    Posts
    5,929

    Re: How to disable Ctrl+V

    Quote Originally Posted by reynen View Post
    My real project is too large to wrap up and send to you. Do you know of anything that could cause this behavior?
    I guess there is other code in your project in effect.
    Anyway, this has nothing to do with TX Text Control .NET, so I suggest to go through your project and check each event that is used.
    Regards,
    Gunnar Giffey, TX Text Control
    [Forum Administrator]

  5. #5
    Join Date
    Feb 2011
    Posts
    19

    Re: How to disable Ctrl+V

    You can override the ProcessCmdKey method of TextControl's ParentForm. Since TextControl provides own handling of some shortcuts, only way I found to manage those keys before it and correctly is in ProcessCmdKey method, because it is handled even before any MenuStrip and ContextMenuStrip can handle it...

    Dusan

  6. #6
    Join Date
    Aug 2010
    Posts
    67

    Re: How to disable Ctrl+V

    Thanks Gunnar and Dusan for your replies. If I found out what my issue is I will post it here for others to benefit from.

    Bill

  7. #7
    Join Date
    Aug 2010
    Posts
    67

    Re: How to disable Ctrl+V

    I found my problem! I had added a context menu to the txtextControl and had defined Ctrl+V one one of the menu items. That was consuming the Ctrl+V event before Key_down.

  8. #8
    Join Date
    Feb 2011
    Posts
    19

    Re: How to disable Ctrl+V

    Quote Originally Posted by reynen View Post
    I found my problem! I had added a context menu to the txtextControl and had defined Ctrl+V one one of the menu items. That was consuming the Ctrl+V event before Key_down.
    I think that is not solution either, because as I wrote, TextControl is handling some shortcuts, so time to time you can get shortcut confict again, since ContextMenu and TextControl has associated same shortcut.

    Code:
        
        // place into code of TextControl's parent form.
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
          if (Control.ModifierKeys == Keys.Control)
          {
            if ((keyData & Keys.KeyCode) == Keys.V)
            {
              ProcessPaste(); 
              return true;
            }
          }
    
          return false;
        }

  9. #9
    Join Date
    Aug 2010
    Posts
    67

    Re: How to disable Ctrl+V

    I get your point but I went to a little effort in this form already to make sure the TextControl always has the focus. But I added the code to the form event as you suggested just to make sure I have it covered.

    Thanks for the advice.

    Bill

Similar Threads

  1. Disable CTRL-Z for UNDO Action
    By schnuddelmeier in forum TX Text Control ActiveX
    Replies: 2
    Last Post: July 7, 2005, 17:26:30
  2. CTRL-A problem
    By fniles in forum TX Text Control ActiveX
    Replies: 1
    Last Post: August 18, 2004, 17:47:15
  3. Ctrl+H keystroke
    By btwes45 in forum TX Text Control ActiveX
    Replies: 7
    Last Post: May 3, 2004, 17:42:32
  4. [SOLVED] Disable Ctrl+V
    By Unregistered in forum TX Text Control ActiveX
    Replies: 1
    Last Post: June 10, 2003, 14:00:42
  5. CTRL + i
    By sdwasson in forum TX Text Control ActiveX
    Replies: 4
    Last Post: February 26, 2003, 15:06:48

Bookmarks

Posting Permissions

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