Set Focus to a Command Button 
Author Message
 Set Focus to a Command Button

Can someone tell me how to set focus to a command button? Thanks a lot.

--
Rob Tomyn



Wed, 26 Jun 2002 03:00:00 GMT  
 Set Focus to a Command Button

Command1.setfocus

If you are trying to set the focus during the form load event and get
an error, it's because you can't set the focus on something that hasn't
loaded yet. Try either setting the focus in the form activate, or
changing that command buttons tab order during the form load so that
it's the first one selected.

Sent via Deja.com http://www.deja.com/
Before you buy.



Thu, 27 Jun 2002 03:00:00 GMT  
 Set Focus to a Command Button
Thank you
One member told me to do
 me.show
then the above statement works  


Thu, 27 Jun 2002 03:00:00 GMT  
 Set Focus to a Command Button
Eww... that could load to major headaches if you load the form by means of
another form.  Don't do that, but rather put the Command1.SetFocus statement
inside the Form's Form_Initialize() event.  I mean, that is entirely what it
is there for.

Howard Henry Schlunder


Quote:
> Thank you
> One member told me to do
>  me.show
> then the above statement works



Thu, 27 Jun 2002 03:00:00 GMT  
 Set Focus to a Command Button


Quote:
> Eww... that could load to major headaches if you load the form by
means of
> another form.  Don't do that, but rather put the Command1.SetFocus
statement
> inside the Form's Form_Initialize() event.  I mean, that is entirely
what it
> is there for.

Errr..  no...  you can not use .SetFocus until the control is visible
and that does not happen until the paint event.  To use it in
Initialize you would have to first Show the form and force the Load,
Paint (and maybe Activate) events to occur first.  Initialize is there
to allow you to initialize module-level variables, not GUI-related
properties.

Sent via Deja.com http://www.deja.com/
Before you buy.



Thu, 27 Jun 2002 03:00:00 GMT  
 Set Focus to a Command Button
Anyway, you might look at Activate event so the button will have the focus
whenever the user returns to the form from elsewhere (other apps). Overkill?
--
Gary, MCT, MCP, MCSD


Quote:


> > Eww... that could load to major headaches if you load the form by
> means of
> > another form.  Don't do that, but rather put the Command1.SetFocus
> statement
> > inside the Form's Form_Initialize() event.  I mean, that is entirely
> what it
> > is there for.

> Errr..  no...  you can not use .SetFocus until the control is visible
> and that does not happen until the paint event.  To use it in
> Initialize you would have to first Show the form and force the Load,
> Paint (and maybe Activate) events to occur first.  Initialize is there
> to allow you to initialize module-level variables, not GUI-related
> properties.

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Thu, 27 Jun 2002 03:00:00 GMT  
 Set Focus to a Command Button


Quote:
> Anyway, you might look at Activate event so the button will have the
focus
> whenever the user returns to the form from elsewhere (other apps).

Overkill?

Activate fires when you swicth between forms in your own application.
Switching to another app and back does not fire any VB event.  You have
to use subclassing to track that if it is important to you.

Sent via Deja.com http://www.deja.com/
Before you buy.



Thu, 27 Jun 2002 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Set Focus to a Command Button

2. Capturing Arrow Keys when Focus is Set to a Command Button

3. Focus rectangle on a command button

4. command button focus problem

5. How to stop focus from going to a Command button

6. Hiding command button focus status

7. Command button focus

8. command button keeping focus

9. Command Buttons, focus, keycode 13, and form loading...

10. Removing rectangle when command button has focus

11. Retaining focus on a command button

12. Command Button Focus

 

 
Powered by phpBB® Forum Software