Click to See Complete Forum and Search --> : VB Command Button focus


Geist
01-05-2003, 04:05 PM
Can you set a command button to not accept any sort of focus? I know that the TabStop property says whether it can accept the focus from the TAB key, but can you have it be clickable but not accept focus?

muisejt
01-06-2003, 09:45 AM
well if you set Default to false, TabStop to false and don't put a & in the name to create a short-cut I don't see how it could get focus unless you added code to give it focus

Geist
01-07-2003, 03:46 PM
If the user clicks the button, the focus is given to the button that was clicked. Any way to prevent this?

ReWarrior
01-08-2003, 08:54 AM
I do not believe you can stop focus from occurring on a command button when the control is clicked. If your issue is that you want to return focus to where it was before the button is clicked perhaps use the gotfocus or lostfocus events on all other controls to log what last had focus and return focus to them at the end of the click event of the button.

ksuohio
01-08-2003, 07:49 PM
What are you trying to do? Might be a better solution to your situation than focusing on just the command button.

df
01-09-2003, 05:49 AM
on the button you dont want focus to get to,
set its focus to something else.


Private Sub Command1_GotFocus()
' code to do stuff here
' move focus to another button.
Command2.SetFocus
End Sub


or you could set the button to disabled

Geist
01-09-2003, 07:38 PM
The idea of setting the focus to another control is a good one. As for my situation, I'm sort of asking generally, but one example is I'm trying to make a very small button that would not need the focus, (like a "windowshade mode" button) and if it has the focus, the focus rectangle makes it look silly and clouds the icon I have on the button.

ReWarrior
01-10-2003, 07:51 AM
The problem with disabling the button, or setting the focus to another control in the onfocus event is that then the button can not be clicked, so why have a button?

Onfocus fires before click. That is why I suggesteda as I did in my previous post.


why not use a picture box to load the icon instaed of a button and put your code in the onclick of this?

Geist
01-12-2003, 02:19 PM
Originally posted by ReWarrior
...why not use a picture box to load the icon instaed of a button and put your code in the onclick of this?
Not a bad idea. Can Picture Boxes receive focus?