selecting/highlighting text in a textbox

the following code should do that.

textBox1.HideSelection = false;
textBox1.Select(0, textBox1.Text.Length);

The first line is important in the case if you don’t have the focus on the textbox, otherwise it seems unselected
this code should do implement a search box on another textbox:

private void textBox4_TextChanged(object sender, EventArgs e)
    var search = textBox4.Text.ToLower();
    var contains = textBox2.Text.ToLower().IndexOf(search);
    if (contains > -1)
        textBox2.HideSelection = false; 
        textBox2.SelectionStart = contains;
        textBox2.SelectionLength = search.Length;

What's your thoughts on this?


Protected by WP Anti Spam