-
November 18th, 2013, 09:08 AM
#1
Key Stroke Limitations
What I need is a text box control that only allows users to paste into (either by using the mouse to right click and paste, or by using Ctrl + V). I also need the user to be able to use the backspace button. I have the following code, but I'm having difficulty trying to figure out how to allow the Ctrl + V functionality, as well as the backspace. It DOES currently allow me to only paste, but only by using the mouse. Could anyone offer some assistance?
Code:
Private Sub TextBox1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.Control AndAlso e.KeyCode = Keys.V Then
Dim testVal As Integer
If Integer.TryParse(Clipboard.GetText, testVal) Then
TextBox1.Text = testVal.ToString
End If
End If
e.Handled = True
e.SuppressKeyPress = True
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As System.EventArgs) Handles TextBox1.TextChanged
Dim testVal As Integer
If Not Integer.TryParse(TextBox1.Text, testVal) Then
TextBox1.Text = ""
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|