|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Setting focus to the FormHello 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? Thanks, Marko. Pygmalion,
You mean to activate a form? http://msdn2.microsoft.com/en-us/library/system.windows.forms.form.activate.aspx Cor Show quoteHide quote "Pygmalion" <ma***@pinteric.com> schreef in bericht news:1166271099.999383.182730@80g2000cwy.googlegroups.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? > > Thanks, Marko. > There is no .Activate method for the Form. Maybe the problem is I use
VisualStudio 6.0? Marko Cor Ligthert [MVP] je napisal: Show quoteHide quote > Pygmalion, > > You mean to activate a form? > > http://msdn2.microsoft.com/en-us/library/system.windows.forms.form.activate.aspx > > Cor > > "Pygmalion" <ma***@pinteric.com> schreef in bericht > news:1166271099.999383.182730@80g2000cwy.googlegroups.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? > > > > Thanks, Marko. > >
Show quote
Hide quote
"Pygmalion" <ma***@pinteric.com> wrote in message The form itself can never have "focus" when there are controls on it that news:1166271099.999383.182730@80g2000cwy.googlegroups.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? 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 MikeD je napisal:
Show quoteHide quote > "Pygmalion" <ma***@pinteric.com> wrote in message Thanks, that solved the problem.> news:1166271099.999383.182730@80g2000cwy.googlegroups.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. > Sorry for dotnet newsgroup. Marko. Show quoteHide quote > -- > Mike > Microsoft MVP Visual Basic Another question. Is it possible to prevent control to obtain keyboard
event? E.g., F8 is defined only for the form. If KeyDown catches that F8 is pressed, it does stuff and disable others to get that key event. Thanks, Marko. Pygmalion je napisal: Show quoteHide quote > > 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. > > "Pygmalion" <ma***@pinteric.com> wrote in message If I understand correctly....assign 0 to the KeyCode parameter.news:1166438198.608551.31150@n67g2000cwd.googlegroups.com... > > Another question. Is it possible to prevent control to obtain keyboard > event? > E.g., F8 is defined only for the form. If KeyDown catches that F8 is > pressed, it does stuff and disable others to get that key event. > > -- Mike Microsoft MVP Visual Basic MikeD je napisal:
Show quoteHide quote > "Pygmalion" <ma***@pinteric.com> wrote in message Yes, you understood correctly. Assigning 0 to KeyCode parameter> news:1166438198.608551.31150@n67g2000cwd.googlegroups.com... > > > > Another question. Is it possible to prevent control to obtain keyboard > > event? > > E.g., F8 is defined only for the form. If KeyDown catches that F8 is > > pressed, it does stuff and disable others to get that key event. > > > > > > If I understand correctly....assign 0 to the KeyCode parameter. > > -- > Mike > Microsoft MVP Visual Basic helped. Thanks, Marko
I want to KEEP trailing zeros
Sending an XML Node to a Function for Processing SP1 Install - was it successful? SQL Server Authentication issues! Anyone know where I can download csharp develepper? Implement Icomparable Windows Service, Process.Start Need some For Loop Next Item How to use Shell Extensions class from Eduardo Morcillo Re: SP1 Install - was it successful? |
|||||||||||||||||||||||