"Pygmalion" <ma***@pinteric.comwrote in message
news:11**********************@80g2000cwy.googlegro ups.com...
>
Hello experts,
I want to use Form_Keydown event in my program. However, it turns out
that one of the form controls is always in focus, so Form_Keydown event
is never invoked. I tried to set focus to the Form using command
frmName.SetFocus in Form_Paint event, however with no effect.
The only successful way I think of to set focus to Form is to .Enable =
False and .Enable = True all controls in Form_Paint event. This works
fine, but is resources and time consuming.
Is there any simpler way to set focus to the Form?
The form itself can never have "focus" when there are controls on it that
can have focus. To do what you want, set the form's KeyPreview property to
True. The form will then receive keyboard events (KeyUp, KeyDown, KeyPress)
before any controls on that form. However, there are some exceptions. For
example, if you have a command button whose Default property is True, the
form will not get the Enter key.
You also said (in another message) that you're using Visual Studio 6
(presumably VB6). Why then did you include a dotnet newsgroup? That's why
you got the answer you did from Cor. THAT was the problem, not that you're
using VB6.
--
Mike
Microsoft MVP Visual Basic