Hello, i want to check what letter is typing by user in textbox in event text change.
Any body know how to do that?
this is my code :

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventHandler) Handles TextBox1.TextChanged
       MessageBox.Show(??)
    End Sub

?? = ?
Please help me! thanks :)

Use the KeyUp event instead...

example:

Private Sub TextBox1_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
		MsgBox(e.KeyCode.ToString)
	End Sub

You also can use the KeyDown event like so:

Private Sub TextBox1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
		If e.KeyCode = Keys.Space Then
			Debug.WriteLine("space is not allowed")
			e.SuppressKeyPress = True
		End If
	End Sub

thanks, but if i hold the key, then just 1 msgbox have launch although there was many letter i was typed. How to resolve it? :)

Private Sub TextBox1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown

		If e.Alt OrElse e.Control OrElse e.Shift Then
			Debug.WriteLine(e.Modifiers.ToString & " => " & e.KeyCode.ToString)
			Return
		End If

		'do your filtering here
		If e.KeyCode = Keys.Space Then
			Debug.WriteLine("space is not allowed")
			e.SuppressKeyPress = True
		End If
	End Sub

owh you right, using the key down event. One more my case : And how to prevent user pressing 1 key and there were more than 1 letter approach in textbox?

look at the example above....

If e.KeyCode = Keys.Space Then
			MsgBox("space is not allowed")
			e.SuppressKeyPress = True
		End If

This prevents the user to type spaces in. of course you have to adjust it to the characters you want to prevent the user from.

thankyou very much :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.