When I click on a button it will keep selected what can I do to deselect the button after click? See the image bellow:
Asked
Active
Viewed 1.2k times
0
-
1is this a windows application or web application ? – Pranav Patel Jun 02 '16 at 10:55
-
1@PranavPatel windows app – Mário Correia Jun 02 '16 at 10:56
-
2Try `this.ActiveControl =
– jitendragarg Jun 02 '16 at 10:57 -
3only one way, after click put focus on another control – Pranav Patel Jun 02 '16 at 11:01
-
1Possible duplicate of [How to remove the focus from a TextBox in WinForms?](http://stackoverflow.com/questions/1140250/how-to-remove-the-focus-from-a-textbox-in-winforms) – gmiley Jun 02 '16 at 11:04
2 Answers
5
private void btnStart_Click(object sender, EventArgs e)
{
btnStop.Focus(); //setting the focus on Stop Button
// ...your code
}
private void btnStart_Click(object sender, EventArgs e)
{
this.ActiveControl = btnStop; //setting the focus on Stop Button
// ...your code
}
private void btnStart_Click(object sender, EventArgs e)
{
Control p;
p = ((Button)sender).Parent;
p.SelectNextControl(ActiveControl, true, true, true, true);
// ...your code
}
Raktim Biswas
- 3,891
- 5
- 25
- 31
-
1I'd like to add something. When embedding UserControl in TabControl requesting focus by userCtrl.Focus() always returns false and focus isn't transferred. But setting this.ActiveControl works flawlessly. – baderman Dec 03 '17 at 18:55
2
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 :
SendKeys.Send("{TAB}");
Beldi Anouar
- 2,162
- 1
- 10
- 16