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

wow, is it me? cant select text in c# textbox

P: n/a
private void button1_Click(object sender, EventArgs e)
{
textBox1.SelectionStart = 0;
textBox1.SelectionLength = textBox1.Text.Length;
}
yet when the button is clicked and there is text in the textbox.... NOTHING.
what am i missing here?
Jul 12 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"S Moran" <s@moran.comwrote in message
news:e$**************@TK2MSFTNGP03.phx.gbl...
private void button1_Click(object sender, EventArgs e)
{
textBox1.SelectionStart = 0;
textBox1.SelectionLength = textBox1.Text.Length;
}
yet when the button is clicked and there is text in the textbox....
NOTHING.
what am i missing here?

In your method, try this instead:

textBox1.Focus();
textBox1.SelectAll();

Jul 12 '07 #2

P: n/a
yup. much nicer (and i apparently had to change the hideSelection property
to false on the textbox)
how can i unselect when the textbox loses focus?

"PvdG42" <pv**@toadstool.eduwrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
>
"S Moran" <s@moran.comwrote in message
news:e$**************@TK2MSFTNGP03.phx.gbl...
>private void button1_Click(object sender, EventArgs e)
{
textBox1.SelectionStart = 0;
textBox1.SelectionLength = textBox1.Text.Length;
}
yet when the button is clicked and there is text in the textbox....
NOTHING.
what am i missing here?


In your method, try this instead:

textBox1.Focus();
textBox1.SelectAll();
Jul 12 '07 #3

P: n/a

"S Moran" <s@moran.comwrote in message
news:OB****************@TK2MSFTNGP03.phx.gbl...
yup. much nicer (and i apparently had to change the hideSelection property
to false on the textbox)
how can i unselect when the textbox loses focus?

Try putting a second TextBox on your form, then a second button. In the
Click event procedure for the new button, set focus to the second TextBox.
You'll see that the text in the first TextBox is automatically deselected
when it loses focus.

Jul 12 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.