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

  • Thread starter Thread starter S Moran
  • Start date Start date
S

S Moran

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?
 
S Moran said:
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();
 
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?
 
S Moran said:
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.
 
Back
Top