selecting text in a textbox

J

John Baro

I have a textbox where I wish the text to be selected when the user clicks
on the textbox.

Textbox.SelectAll();

or

Textbox.SelectionStart = 0;
Textbox.SelectionLength = Textbox.Text.Length;

Neither work if the user clicks.
Both work if the user tabs
or I set focus in code.

:(

JB
The greatest arrogance of humankind was to believe they were unique.
 
C

C# Learner

John said:
I have a textbox where I wish the text to be selected when the user clicks
on the textbox.

Textbox.SelectAll();

<snip>

Try this:

textBox_MouseUp(...)
{
textBox.SelectAll();
}

That should fix the whole problem for you, since "tabbing" to a text box
automatically selects all the text.
 
J

John Baro

Love your work CSL.
Thanks
JB
C# Learner said:
<snip>

Try this:

textBox_MouseUp(...)
{
textBox.SelectAll();
}

That should fix the whole problem for you, since "tabbing" to a text box
automatically selects all the text.
 

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