By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,213 Members | 1,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,213 IT Pros & Developers. It's quick & easy.

Textbox: Select Text On Tabed Focus

P: n/a
I thought when you tabbed into a textbox that the text it contained
was automatically highlighted. This use to be the default in win32.

Is there an easy way to do this in .NET. I don't want this to happen
if the mouse is used to select the TextBox.

Seems wierd, If the Textbox has the default text in it the higlight
works but not if you edit it.

Thanks.
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Phill,

You can set textBox1.SelectAll() in the Enter event,
or if you use the same Enter event for all your textboxes

private void textbox_Enter(object sender, EventArgs e)
{
((TextBox)sender).SelectAll();
}

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2

P: n/a

calling SelectAll() on all your text boxes in the Page_Load should do the
trick

You'll only see the selection of the textbox that has focus, tabbing keeps
the selection, while a mouse click selects the mouse click, which, if is not
a drag, simply inserts the caret.
"Phill" <wa********@yahoo.com> wrote in message
news:ac**************************@posting.google.c om...
I thought when you tabbed into a textbox that the text it contained
was automatically highlighted. This use to be the default in win32.

Is there an easy way to do this in .NET. I don't want this to happen
if the mouse is used to select the TextBox.

Seems wierd, If the Textbox has the default text in it the higlight
works but not if you edit it.

Thanks.

Nov 16 '05 #3

P: n/a
On the Enter event for the TextBox, you call SelectAll(). This will have the
effect you want. Clicking will place the mouse wherever you clicked without
selecting. You can program the event once and attach it to all TextBoxes on
your form.

private void textBox_Enter(object sender, System.EventArgs e)
{
txt = sender as TextBox;
if ( txt != null )
txt.SelectAll();
}

Or you can do a simple class than inherits from TextBox, and provide this
behavior if you need it in many places.

-Rachel

"Phill" <wa********@yahoo.com> wrote in message
news:ac**************************@posting.google.c om...
I thought when you tabbed into a textbox that the text it contained
was automatically highlighted. This use to be the default in win32.

Is there an easy way to do this in .NET. I don't want this to happen
if the mouse is used to select the TextBox.

Seems wierd, If the Textbox has the default text in it the higlight
works but not if you edit it.

Thanks.

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.