How to Remove Focus Without Setting Focus to Another Control

Destroy/completely remove focus programmatically

You could always use:


How to remove focus from currently focused component?

You could use:

procedure TCustomForm.DefocusControl(Control: TWinControl; Removing: Boolean);

Remove focus from textbox when it is only editable control

set the text box to:

tabindex = -1


tabstop = false

The above depends on the type of control you are using, whether it is a asp control or html control.
Then add a label like:

<label id="lblHide" name="lblHide" hidden="hidden">

then set focus to that label.


So, here's what it will look like for you:

<asp:TextBox ID="TextBox1" runat="server" TabIndex="-1" ReadOnly="True"></asp:TextBox>
<asp:Label ID="Label1" runat="server"></asp:Label>

and then on page load this:

protected void Page_Load(object sender, EventArgs e)

WPF: How to programmatically remove focus from a TextBox

in .NET Framework 4 just Keyboard.ClearFocus();

Setting Focus on another control on button click

You need some other focusable control to move the focus to like your StopButton.

you can set btnStop.Focus () ;

You can also set the forms activecontrol property to null like

 this.ActiveControl = null;

Or using Tab order after set up order :


remove focus from a button which was clicked

You simply put the focus on another window by calling ::SetFocus (or CWnd::SetFocus if you are using MFC) with the desired window's handle/pointer.

Related Topics

Leave a reply