how do i shift focus?

G

Guest

when the user log into my application, there is a dialog pop up with some
paramereters that need to set.

a radio button is default to checked and a textbox is right next to it. i
want the cursor or the ibeam to flash on the textbox so user don't have to
click on the textbox in order to enter input. how do i shift the focus?

i have the windows form load even with

this.rdTest.enabled = true;
this.txtTest.enabled = true;
this.txtTest.focus();

but it doesn't show the ibeam on the textbox. Can someone tell me how to do
this?

thank you.
 
J

Jani Järvinen [MVP]

Hello!
txtTest.Select()

Correct, calling the Select method does the trick. Another option would be
to say:

this.ActiveControl = txtTest;

However, the way I read the original poster's question, he/she might also
want to consider setting the tab order correctly, in which case calling
Select in the Form_Load event is not necessary. The easiest way to set the
tab order with Visual Studio is to choose the View/Tab Order menu command on
the form design view, and then click the controls one by one in correct
order. Focus (the "ibeam") will then go to the first-clicked control
automatically without any code.

Also, a note about Focus vs. Select methods. From the class library
reference documentation:

"Focus is a low-level method intended primarily for custom control authors.
Instead, application programmers should use the Select method or the
ActiveControl property [...]"

This in addition to what Ciaran has already said.

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
(e-mail address removed)
http://www.saunalahti.fi/janij/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top