Can I do this - Control Focus despite Tab Order ?
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.windowsforms.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

JB
Using the tab order in VB on a form works fine but to me it seems
tedious (at times) to have to set or be concerned with the tab order.
I can't seem to get a control to have focus on the load form
event...am I doing something wrong or do I just need to control this
thru tab order?

TIA

JB
Reply to this message...
 
    
Imran Koradia (VIP)
The form is shown only after the last line in the load event is executed.
During the load event, the form is invisible and so are the controls on it.
Focus can only be set on controls that are visible and enabled. So trying to
set focus to a control in the load event wont work. Instead, use the
Activated event of the form to set focus. However, since Activated is fired
everytime the form is activated, you'll have to make sure that you set focus
only the first time it is activated which is after the load event. Something
like this should work for you:

Private bFirstTimeActivated as boolean

Private Sub Form1_Activated(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Activated
If Not bFirstTimeActivated Then
MyControl.Focus()
bFirstTimeActivated = True
End If
End Sub

hope this helps..
Imran.

"JB" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
JB
Thanks for the explanation...makes sense. I'll give your method a
try.

One other thing that I discovered right after I posted my original
message was the "Tab Order" found under the View menu when in Design
mode. This feature takes the tediousiness out of setting tab order.

JB

"Imran Koradia" <Click here to reveal e-mail address> wrote in message news:<Click here to reveal e-mail address>...
[Original message clipped]

Reply to this message...
 
 
System.EventArgs




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com