Focus

  • Thread starter Thread starter Patrick De Ridder
  • Start date Start date
P

Patrick De Ridder

I have a form with a number of text boxes. When I start the program I
want the cursor to be in one particular text box. I have tried
textbox4.Focus(); in the constructor, but that doesn't do the trick.
How should it be done?
Many thanks,
 
Hi Patrik
Try to set Textboxes' TabIndex properties properly. The text box with tab
index 0 should have the focus when you start the form. Make sure TabStop is
set to true for all text boxes

HTH
B\rgds
100
 
100 said:
Hi Patrik
Try to set Textboxes' TabIndex properties properly. The text box with tab
index 0 should have the focus when you start the form. Make sure TabStop is
set to true for all text boxes

Thanks! I will do that.
Btw what does TabStop do?
 
Alternatively, you can call the .Focus() method from within the Form_Load
event.

Cheers,
Wim Hollebrandse
 
Wim Hollebrandse said:
Wow - that's very unexpected behavior indeed.

I did have a play around, and found a solution. You can set the
ActiveControl property of the Form object.

For instance (assuming this is the current Form reference):

this.ActiveControl = this.textBox1;
I will try it. Many thanks.
 
Hi Patrick,
The following is a quote from the MSDN about Control's TabStop property

When the user presses the TAB key, the input focus is set to the next
control in the tab order. Controls with the TabStop property value of false
are not included in the collection of controls in the tab order. The tab
order can be manipulated by setting the control's TabIndex property value.

HTH
B\rgds
100
 
Back
Top