将焦点设置在按钮单击的另一个控件上

Már*_*eia 0 c# button winforms

当我点击一个按钮时,它将保持选中,点击后如何取消选择按钮?见下图:

选择按钮启动如何在单击后删除选择?

Rak*_*was 5

聚焦方法

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

    // ...your code
}
Run Code Online (Sandbox Code Playgroud)

ActiveControl属性

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

    // ...your code
}
Run Code Online (Sandbox Code Playgroud)

SelectNextControl方法

private void btnStart_Click(object sender, EventArgs e)
{
    Control p;
    p = ((Button)sender).Parent;
    p.SelectNextControl(ActiveControl, true, true, true, true);

    // ...your code
}
Run Code Online (Sandbox Code Playgroud)