0
votes

So the scenario that I have is that there is a Form with three text boxes and a button. Clicking the button sets textBox1.Enabled = false, textBox2.Enabled = false, and textBox3.Focus().

enter image description here

The problem that I'm running into is that if either textBox1 or textBox2 has focus at the moment the user clicks the button, the text box becomes disabled but retains a greyed-out version of the focus rectangle. It's like the form isn't redrawing the disabled text box. Please observe the attached screenshot and notice the difference between the first and second text box.

How do I ensure that I move focus to textBox3 and get rid of the focus rectangle around textBox1?

1

1 Answers

2
votes

I'm not sure if this behavior is a bug, but i found way to handle it. The trick is play around with BorderStyle property.

private void button1_Click(object sender, EventArgs e)
{
    textBox3.Focus();
    var borderStyle = textBox1.BorderStyle;
    textBox1.BorderStyle = BorderStyle.None;
    textBox2.BorderStyle = BorderStyle.None;
    textBox1.Enabled = false;
    textBox2.Enabled = false;
    textBox1.BorderStyle = borderStyle;
    textBox2.BorderStyle = borderStyle;
    textBox1.Refresh();
}