2

When I click on a button it will keep selected what can I do to deselect the button after click? See the image bellow:

Button start is selected how to remove the selection after click?

Raktim Biswas
  • 4,011
  • 5
  • 27
  • 32
Mário Correia
  • 51
  • 1
  • 1
  • 8

2 Answers2

8

Focus Method

private void btnStart_Click(object sender, EventArgs e)
{
    btnStop.Focus(); //setting the focus on Stop Button

    // ...your code
}

ActiveControl Property

private void btnStart_Click(object sender, EventArgs e)
{
    this.ActiveControl = btnStop; //setting the focus on Stop Button

    // ...your code
}

SelectNextControl Method

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
  • 4,011
  • 5
  • 27
  • 32
  • 1
    I'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,170
  • 1
  • 12
  • 17