TextBox to have contents Selected when you tab into it

  • Thread starter Thread starter Barry Flynn
  • Start date Start date
B

Barry Flynn

VB 2005 - Windows Forms program.

I have a form with two textboxes.
One has been there for a long time, and when I tab into it, the contents are
automatically Selected.
I've just added a new textbox, and this does not happen.
I can see no difference in the properties of the two textboxes.

If I create a 3rd textbox by copying the original one, it too does not have
its contents Selected when I tab into it.

What is it that specifies whether textbox's text will be Selected when you
tab onto it?

Thanks

Barry
 
Barry Flynn said:
VB 2005 - Windows Forms program.

I have a form with two textboxes.
One has been there for a long time, and when I tab into it, the contents
are automatically Selected.
I've just added a new textbox, and this does not happen.
I can see no difference in the properties of the two textboxes.

If I create a 3rd textbox by copying the original one, it too does not
have its contents Selected when I tab into it.

What is it that specifies whether textbox's text will be Selected when
you tab onto it?

Thanks

Barry

I don't believe there is a property for this. This is usuallly accomplished
by writing an event handler for the textbox's "Enter" event and writing code
that selects the text for you. It's been a while since I did this, but the
code was something like this:

textbox.selstart = 0
textbox.sellength = textbox.text.length

-Scott
 
Thanks

Barry


Scott M. said:
I don't believe there is a property for this. This is usuallly
accomplished by writing an event handler for the textbox's "Enter" event
and writing code that selects the text for you. It's been a while since I
did this, but the code was something like this:

textbox.selstart = 0
textbox.sellength = textbox.text.length

-Scott
 
VB 2005 - Windows Forms program.

I have a form with two textboxes.
One has been there for a long time, and when I tab into it, the contents are
automatically Selected.
I've just added a new textbox, and this does not happen.
I can see no difference in the properties of the two textboxes.

If I create a 3rd textbox by copying the original one, it too does not have
its contents Selected when I tab into it.

What is it that specifies whether textbox's text will be Selected when you
tab onto it?

I would look at events for the Textbox that selects the text. My
guess is that some event like Enter has code to do the selection.
 
When I investigated this a bit further, I found something interesting (at
least I found it interesting.)
I looked at the textbox in which text was "selected" when I tabbed into it.
There was no code in any of its events.
However, it did have its initial contents "programatically set" - ie
TextBox.Text = "Blah blah".
And that appeared to do it.

If I set the contents of the text box with that statement, then when I tab
into it, the text is Selected.
As soon as I manually change the contents, that behaviour ceases - it is no
longer Selected when I tab into it.

I realize that I could put code in an event like Enter to vary that
behaviour - but that's how it appears to behave by default.

Barry
 
Back
Top