Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

enter key as a tab

Status
Not open for further replies.

michelleHEC

Programmer
Oct 20, 2003
95
US
my code to have an enter key work as a tab key worked at first but now it will not work. has anyone any ideas? here is the code.

Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
Dim ctl As Control = Me.ActiveControl

If TypeOf ctl Is TextBox And e.KeyValue = Keys.Enter Then
Me.SelectNextControl(ctl, True, True, True, True)
e.Handled = True
End If
End Sub
thanks,
Michelle
 
The only thing that I can think of that would stop it from working would be that you have accidently changed KeyPreview on the form back to False - it has to be True for your code to work.



Hope this helps.

[vampire][bat]
 

I had set it to true already and it still is true. so wierd for it to work and then all of a sudden, stop working.
thanks for the reply though!
michelle
 
Is the event firing?

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
yes
and when I step through it the e.KeyValue = Keys.Enter are both 13 and the ctl is textbox but it fails the if statement.
 
Change And to AndAlso in the if statement or use parentheses:

If TypeOf ctl Is TextBox AndAlso e.KeyValue = Keys.Enter Then

If (TypeOf ctl Is TextBox) And (e.KeyValue = Keys.Enter) Then

maybe that'll work

Regards, Ruffnekk
---
Is it my imagination or do buffalo wings taste just like chicken?
 

neither worked. what is really weird is that it worked at first but when I deployed it that is when it stopped working...
 


ok I have it working but I had to take out this part...

TypeOf ctl Is TextBox and

I still don't know why that was stopping it but at least now it is working.

Thanks again for all your help.
Michelle
 
Is this correct?
Code:
Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
or maybe be
Code:
Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Regards
 
the top one is the one I am using. it sees the procedure just wouldn't give the textbox boolean a true value but once I removed that it worked.
 
well then I'm curious about what is returned if you insert a messagebox:

Code:
Dim ctl As Control = Me.ActiveControl
MsgBox(ctl.ToString)

The result should be something similar to:

"System.Windows.Forms.TextBox, Text: TextBox1"

Regards, Ruffnekk
---
Is it my imagination or do buffalo wings taste just like chicken?
 
That makes it even more odd that "TypeOf ctl Is TextBox" is not returning True... beats me for now :)

Regards, Ruffnekk
---
Is it my imagination or do buffalo wings taste just like chicken?
 

I know, but since I have it working without the "TypeOF ctl is TextBox" I am going to move on to my new thing I cannot get working!
 
Ok I'll be on the watch for a new topic by you then *lol*

Regards, Ruffnekk
---
Is it my imagination or do buffalo wings taste just like chicken?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top