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

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?
 
P

PvdG42

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();
 
S

S Moran

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?
 
P

PvdG42

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.
 

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