Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / September 2005

Tip: Looking for answers? Try searching our database.

Up Down Arrows as TAB Key

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bob - 31 Aug 2005 13:05 GMT
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
Some Guy - 31 Aug 2005 15:13 GMT
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

> Hello:
>
[quoted text clipped - 14 lines]
>
> Bob
Bob - 01 Sep 2005 13:12 GMT
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
Some Guy - 01 Sep 2005 17:24 GMT
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

> Some Guy:
>
[quoted text clipped - 20 lines]
>
> Bob
hayworth@hotmail.com - 02 Sep 2005 15:29 GMT
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.
Bob - 02 Sep 2005 16:07 GMT
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
hayworth@hotmail.com - 30 Sep 2005 18:59 GMT
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.
Bob - 02 Sep 2005 16:16 GMT
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
Some Guy - 02 Sep 2005 17:10 GMT
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

> Mark:
>
[quoted text clipped - 20 lines]
>
> Bob
Bob - 02 Sep 2005 20:43 GMT
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
Bob - 02 Sep 2005 20:46 GMT
Some guy:

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

Thanks again

Bob

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.