Search code examples
c#.netwinformstextboxfocus

How to remove the focus from a TextBox in WinForms?


I need to remove the focus from several TextBoxes. I tried using:

textBox1.Focused = false;

Its ReadOnly property value is true.

I then tried setting the focus on the form, so as to remove it from all the TextBoxes, but this also fails to work:

this.Focus();

and the function returns false when a textbox is selected.

So, how do I remove the focus from a TextBox?


Solution

  • You can add the following code:

    this.ActiveControl = null;  //this = form