textbox and enter event

  • Thread starter Thread starter Chris Wertman
  • Start date Start date
C

Chris Wertman

This seems like a simple one, ive searched the msdn and groups and cant
come up with the answer however.

I dont build gui apps very often (actually this is my first in oh 3
years)

I have a form and a textbox

When I put text in it and press enter I want it to DO SOMETHING, but I
cant find what event that is. When I press enter I just get the dink
sound. nothing happens, I tried the textchanged but that isnt it. This
is the only text box on the form

Ive been trying to figure this out for the last hour, and I cant imagine
what event this is.

The NEXT question I have is how would I fire an event that transforms
the input once a user has entered 10 digits ? But that second, if I cant
figure out the first it useless

Chris
 
You can trap KeyDown and/or KeyPress events. KeyDown will occur first. You
can then use the properties of the xxxEventArgs, either e.KeyCode for
KeyDown (there's a bunch of others too) or e.KeyChar

HTH,

Bill
 
William said:
You can trap KeyDown and/or KeyPress events. KeyDown will occur
first. You can then use the properties of the xxxEventArgs, either
e.KeyCode for KeyDown (there's a bunch of others too) or e.KeyChar

If you want to get rid of the beep sound, you *must* trap the KeyPress event
and set e.Handled = True.

Doing this in the KeyDown event won't get rid of the sound.
 
Hi Sven:

I agree with you. I thought he was asking how to do 'something' in a generic
sense when enter is pressed. From the post I gathered that he didn't want
to cancel the event, rather he was having trouble finding which event is
fired and "textchanged" wasn't doing it.

Either way, you raise a good point.
 
Yeah that got it, looking on those keywords I found this

Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
Dim keyCode As Int32 = Convert.ToInt32(e.KeyChar)
If keyCode = 13 Then

CheckedListBox1.Items.Add(TextBox2.Text)

End If

End Sub

Minus the french comments and supporting text, gotta love code, dosent
really matter what language you speak you can read it

Beyond KeyPress was what I was looking for as my barcode scanner I am
using about 50% of the time to enter in this field will send the ascii
13 at the end of the code.

once again duh......

Thanks all you guys are a lifesaver

Chris
 
Chris said:
Dim keyCode As Int32 = Convert.ToInt32(e.KeyChar)

I'd just like to add that the conversion to character code isn't necessary.
You can just compare e.KeyChar directly to ControlChars.Cr. It makes it more
clear which char you're checking for too.
Thanks all you guys are a lifesaver

You're welcome. ^_^
 
Back
Top