Problems setting input focus from the Load handler

  • Thread starter Thread starter Steve Sargent
  • Start date Start date
S

Steve Sargent

Hi:

I'm trying to develop a message reply form, and I want the reply form
to automatically be set to the text, with the cursor at the end of the
current text.

I basically use the following lines to do it:

this.textBox3.Focus();
this.textBox3.SelectionStart = this.textBox3.Text.Length;
this.textBox3.SelectionLength = 0;

This code works when I test it using the button click handler. the
minute I click the button, textBox3 gets the input focus, and the
cursor is at the end of the current text.

However, when calling from the Load method, it doesn't change the
focus at all.

Where should I be adding this code so that when the form first shows
up on the screen, the input focus is at the end of textBox3's text?

Thanks for any help.

Steve
 
In VB6 I also did that in the Load event.
In VB.NET it seams that that is to soon ... meaning that you have to wait
until the form is shown.
Therefore I now always do that in the Activate event.

Regards,

--

Nico Debeuckelaere (MVP VB.NET)

ND-Sign BVBA (Microsoft Certified Partner since 2004)
Pierstraat 135
B-2840 Rumst
URL: http://www.nd-sign.com
== ND-Sign, Designed for you ==
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Thank you for the help. That worked.

Steve


In VB6 I also did that in the Load event.
In VB.NET it seams that that is to soon ... meaning that you have to wait
until the form is shown.
Therefore I now always do that in the Activate event.

Regards,

--

Nico Debeuckelaere (MVP VB.NET)

ND-Sign BVBA (Microsoft Certified Partner since 2004)
Pierstraat 135
B-2840 Rumst
URL: http://www.nd-sign.com
== ND-Sign, Designed for you ==
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
* I_hate_spammers@spammers_suck.com (Steve Sargent) scripsit:
I'm trying to develop a message reply form, and I want the reply form
to automatically be set to the text, with the cursor at the end of the
current text.

I basically use the following lines to do it:

this.textBox3.Focus();
this.textBox3.SelectionStart = this.textBox3.Text.Length;
this.textBox3.SelectionLength = 0;

This code works when I test it using the button click handler. the
minute I click the button, textBox3 gets the input focus, and the
cursor is at the end of the current text.

However, when calling from the Load method, it doesn't change the
focus at all.

The focus can be set only if the window is visible. Call the form's
'Show' method prior to the call to the focus method.

\\\
Me.Show()
Me.Refresh()
///
 
Back
Top