By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 992 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

Up Down Arrows as TAB Key

P: n/a
Bob
Hello:

I'm tring to make the down arrow act as a tab key and the up arrow act as
like (-TAB.).

I have this for the down arrow but nothing happens.

Protected Overrides Function ProcessDialogKey(ByVal keyData As Keys) As
Boolean
MyBase.ProcessDialogKey(keyData)
If keyData = System.Windows.Forms.Keys.Down Then
keyData = System.Windows.Forms.Keys.Tab
End If
End Function
TIA

Bob
Nov 21 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Put the call to the MyBase.ProcessDialogKey(keyData) AFTER the if
statement.

Protected Overrides Function ProcessDialogKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean
If keyData = Keys.Down Then
keyData = Keys.Tab
End If
MyBase.ProcessDialogKey(keyData)
End Function
"Bob" <no****@nospammers.com> wrote in message
news:C2hRe.26816$FL1.13685@trnddc09...
Hello:

I'm tring to make the down arrow act as a tab key and the up arrow act as
like (-TAB.).

I have this for the down arrow but nothing happens.

Protected Overrides Function ProcessDialogKey(ByVal keyData As Keys) As
Boolean
MyBase.ProcessDialogKey(keyData)
If keyData = System.Windows.Forms.Keys.Down Then
keyData = System.Windows.Forms.Keys.Tab
End If
End Function
TIA

Bob

Nov 21 '05 #2

P: n/a
Bob
Some Guy:

Strange how my original post didn't show up where I intended. Thanks for the
response despite my screw up.

Your sugextion looks like it should work based on other articles. I'm
thinking I'm missing one little bit of this. Maybe I'm putting it in the
wrong place in my code.

I tried calling it from a controle like this

Dim MyKey As System.Windows.Forms.Keys
MyBase.ProcessDialogKey(MyKey)

Yet nothing happens. I would like it to work through out the whole form. Do
I need to raise the event somewhere? Also, will it slow things down or would
I be better to try to convince the client to use traditional methods to
navigate the controles. Please keep in mind I have 327 controles.

Thanks Again

TIA

Bob
Nov 21 '05 #3

P: n/a
This code sets MyKey to none. So nothing happens.

Dim MyKey As System.Windows.Forms.Keys
MyBase.ProcessDialogKey(MyKey)

Try: Dim MyKey As System.Windows.Forms.Keys=Keys.Tab

"Bob" <no****@nospammers.com> wrote in message
news:ZeCRe.7650$__1.4593@trnddc07...
Some Guy:

Strange how my original post didn't show up where I intended. Thanks for
the response despite my screw up.

Your sugextion looks like it should work based on other articles. I'm
thinking I'm missing one little bit of this. Maybe I'm putting it in the
wrong place in my code.

I tried calling it from a controle like this

Dim MyKey As System.Windows.Forms.Keys
MyBase.ProcessDialogKey(MyKey)

Yet nothing happens. I would like it to work through out the whole form.
Do I need to raise the event somewhere? Also, will it slow things down or
would I be better to try to convince the client to use traditional methods
to navigate the controles. Please keep in mind I have 327 controles.

Thanks Again

TIA

Bob

Nov 21 '05 #4

P: n/a
keyData is passed in by value, so how can you change it? I don't
believe you can change the value of an argument unless it has been
passed in by reference, so I don't believe your function will actually
change the value of keyData. In fact, I'm surprised you don't get an
exception there.

I think you have to use the focus method to change focus, something
like
If keyData = System.Windows.Forms.Keys.Down Then
cmdNextButton.Focus()
End If
And I think you'd have to keep track of the order you want the tabs to
go in, or else search all the control properties yourself to find out
which one should get focus next and then manually set focus to that
particular control. In VB6 I've used a function (API function I think)
called SendKeys. Perhaps you can use that to send a tab to your
application whenever it sees a down arrow. I've not used it yet in
vb.net. Perhaps something like (not sure of the SendKey args):
If keyData = System.Windows.Forms.Keys.Down Then
SendKeys(application.hInstance,
System.Windows.Forms.Keys.Tab)
End If

Good luck.
Mark H.

Nov 21 '05 #5

P: n/a
Bob
Some Guy & Mark:

Thanks to both of you for the responses. Some Guy's response actually made
it so all the keys acted as a TAB key. However, this gave me some leads to
work with and helped me figure it out.

Mark.

I certainly see what you mean and when you look below at the code that is
working, you'll fall of your chair. I still have not fully tested it but so
far it works ok with one small yet probably resolvable issue. I've yet to
have any errors at all.

Protected Overrides Function ProcessDialogKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean
'MyBase.ProcessDialogKey(keyData) <<--Note that this line is
comented out.
End Function

'If I remove the above function entirely, the down arrow does nothing. Even
when I press it in other Private Subs for 'KeyDown events in other controles
and the TAB key doesn't work at all. Strange don't you think?

Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Dim MyKey As System.Windows.Forms.Keys
If e.KeyCode = Keys.Down Then
MyKey = Keys.Tab
ElseIf e.KeyCode = Keys.Tab Then
MyKey = Keys.Tab
End If
MyBase.ProcessDialogKey(MyKey)
End Sub

The one small issue to resolve as of now is the following

I have an inherited user controle I made. It's a TextBox that I set to
MultiLine = True and ScrollBars = Verticle in my application(Not when I
built the controle). It's designed to move to the upper left portion of the
form and resize to (636, 326) when the F1 key is pressed and return to it's
original size and position when ESC is pressed. This also continues to
function as it should.

The down arrow acts as a TAB key intill it encounters my controle. When the
cursor reaches my controle, the down arrow key does nothing untill I press
the TAB key or click the next controle. Then the down arrow again functions
as the TAB key. However, the TAB key continues to function normally through
out all the controles on the form.

YEAH, I'm scratching my head too.

Bob
Nov 21 '05 #6

P: n/a
Bob
Mark:
I think you have to use the focus method to change focus, something like If keyData = System.Windows.Forms.Keys.Down Then
cmdNextButton.Focus()
End If
I forgot to mention,

That would take a lot of code as I have more than 327 controles on my form
that TabStop = True. I must intercept the Down Arrow key press in the forms
KeyDown event.
If keyData = System.Windows.Forms.Keys.Down Then
SendKeys(application.hInstance, System.Windows.Forms.Keys.Tab)
End If


Now thats interesting. I may able to refine my code with what you gave me.
I'll be sure and post my results.

Thank you

Bob
Nov 21 '05 #7

P: n/a
What's the problem?

Protected Overrides Function ProcessDialogKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean
If keyData = Keys.Up Then
keyData = Keys.Tab
MyBase.ProcessDialogKey(keyData)
End If
End Function

"Bob" <no****@nospammers.com> wrote in message
news:41_Re.229$AB4.42@trnddc03...
Mark:
I think you have to use the focus method to change focus, something like

If keyData = System.Windows.Forms.Keys.Down Then
cmdNextButton.Focus()
End If


I forgot to mention,

That would take a lot of code as I have more than 327 controles on my form
that TabStop = True. I must intercept the Down Arrow key press in the
forms KeyDown event.
If keyData = System.Windows.Forms.Keys.Down Then
SendKeys(application.hInstance, System.Windows.Forms.Keys.Tab)
End If


Now thats interesting. I may able to refine my code with what you gave me.
I'll be sure and post my results.

Thank you

Bob

Nov 21 '05 #8

P: n/a
Bob
Some Guy:

There is no problem. You've been a great help. Someone else responded also
and maybe he didn't see your post so maybe he thought is wasn't resolved. He
didn't seem to think it would work at all but actually it works great. It
was just hanging on one of my inherited user controles but I fixed that too
with a little modification to my controle.

Thanks for helping

Bob
Nov 21 '05 #9

P: n/a
Bob
Some guy:

I'm sorry. My response was to Marks response. HEHEHE. Everything is fine.

Thanks again

Bob
Nov 21 '05 #10

P: n/a
Bob:
Your new code should work now because you are no longer changing the
key that was passed in by value. You're making a new vairable MyKey
and then (recursively sort of) calling the function again but with
MyKey instead of the original key. I think this should work.

Not exactly sure about your other problem but maybe since it's a text
field it's different. Maybe the text field has focus and is expecting
you to type something into it, and it thinks the arrow key is just like
any other key you might want to type, like regular letters, etc. You
might have to make this a special case and put some code into the event
(if it has one) for that control that gets fired off when the value
changes.
Mark H.

Nov 21 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.