I have a text box and I want to check if any value is pasted in it ?
I am already using its Keypress event to check that any value is inserted in it or not?
But i want to check that a value is pasted in it not?
I have a text box and I want to check if any value is pasted in it ?
I am already using its Keypress event to check that any value is inserted in it or not?
But i want to check that a value is pasted in it not?
As for as I understand you said that you have already use TextBox Keypress event and now you want to check if a value is pasted in TextBox or not
If you are pasting your value thorough mouse than may be this will work fine
Private Sub TextBox_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox.MouseDown
If e.Button = Windows.Forms.MouseButtons.Right Then
//Code here what you want to do
End If
End Sub
Note this will help you if you are pasting your value through mouse right click
You may have to do this manually... with some "creativity"
Dim lastProperText As String = ""
In your keypress event, save the last text you are satisfied with, after you ahve "handled" the input...
Textbox_Keypress
'your code here that filters out what you don;t want to handle...
lastProperText = textbox.text
/Textbox_Keypress
Then, in your textbox_textchanged event (This will fire after a paste has occured), compare the new text to your required format, if not in the required format, then set your textbox back to the last "good" text.
textbox.text = lastProperText
See this answer for reference: