Deny Ctrl-V

  • 14 years ago

    how can I disable the combo CTRL-V so a user cant paste into a textbox without disabling all control keys?

    I disabled right clicking and pasting by creating a new context menu, now I just need to stop it from happening with the keyboard.

  • 14 years ago

    Your textbox should have a 'ShortcutsEnabled' property.  Set that to false and the cut/paste context menu as well as Ctrl-V and Ctrl-C will be disabled.  I use Visual Studio 2005 so that may be a 2005 thing.  If you don't have that property you can disable a combination of keys.  Here is the code needed to suppress Ctrl-V and Ctrl-C.

        Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
            'Suppress Ctrl-V and Ctrl-C
            If e.Control AndAlso (e.KeyCode = Keys.V OrElse e.KeyCode = Keys.C) Then e.SuppressKeyPress = True
        End Sub

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.” - Antoine de Saint Exupéry