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

时间:2016-06-02 10:53:31

标签: c# winforms button

当我点击一个按钮时,它会保持选中状态,点击后取消选择按钮该怎么办?见下图:

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

2 个答案:

答案 0 :(得分:4)

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
}

答案 1 :(得分:1)

您需要一些其他可调焦控件才能将焦点移至StopButton

您可以设置btnStop.Focus () ;

您还可以将窗体activecontrol属性设置为null,如

 this.ActiveControl = null;

或在设置订单后使用Tab顺序:

SendKeys.Send("{TAB}");