You can also call the Focus() method of a specific control, provided that
control's CanFocus property is true. Focus() returns a bool based on
success or failure; if CanFocus == false then Focus() will always return
false.
In my experience all "out of the box" WinForms controls will respond
correctly to Focus() even when the form hasn't been shown yet, but some
third party controls will not do this until the form is shown (specifically,
I've seen this with controls from Infragistics). So if you ever want to set
initial focus on a new form based on some condition or other, it's safest to
do that in the form's Activate event rather than in the Load event or from
somewhere outside the form before it's shown.
--Bob
"Tom Porterfield" <tp******@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
ch***@ckerrison.freeserve.co.uk wrote: Does anybody know how I can programmatically cause a textbox to lose
focus and automatically jump to the next appropriate control.
I have a custom textbox usercontrol whereby the requirement is to
enable the user to jump around between controls by hitting the enter
key instead of tab key or mouse.
Assuming your control derives from System.Windows.Forms.Control. Look at
calling the SelectNextControl method on the Form object that the instance
of your control is on in an override OnKeyPress. You can call your
FindForm method to get the form that your control is on.
--
Tom Porterfield