toolStripButton点击后保持焦点

    int index;

    private void toolStripButton1_Click(object sender, EventArgs e)
    {
        index = 1;
        Console.WriteLine("1111\n1111111\n111111");
        SetFocus();
    }

    private void toolStripButton2_Click(object sender, EventArgs e)
    {
        index = 2;
        MessageBox.Show("2");
        SetFocus();
    }

    private void toolStripButton3_Click(object sender, EventArgs e)
    {
        index = 3;
        MessageBox.Show("3");
        SetFocus();
    }

    private void SetFocus()
    {
        // Send key Tab and Right
        SendKeys.Send("{Tab}");
        for (int i = 0; i < index - 1; i++)
        {
            SendKeys.Send("{Right}");
        }
    }

Or

private void toolStripButton1_Click( object sender, EventArgs e )
{
    ....
    var b = (ToolStripButton)sender;
    BeginInvoke( new Action( () => b.Select() ) );
}
posted @ 2019-03-07 16:15  Kyle0418  阅读(494)  评论(0编辑  收藏  举报