winforms 我如何在windowsForms应用程序中更改选定的textBox

hzbexzde  于 2023-01-17  发布在  Windows
关注(0)|答案(1)|浏览(164)

我希望用户能够通过点击Keys.EnterKeys.UpKeys.Down在文本框和按钮之间移动。有没有类似this.SelectedItem = TxtBoxName的方法?

private void TxtBoxName_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
        {
            if(TextIsEmpty(TxtBoxDebt.Text))
            {
                //switch to TxtBoxDebt
            }
            else
            {
                AssignNewPerson();
            }
        }
        if (e.KeyCode == Keys.Down)
        {
            //switch to TxtBoxDebt
        }
    }
    private void TxtBoxDebt_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
        {
            AssignNewPerson();
        }
        else if (e.KeyCode == Keys.Up)
        {
            //switch to TxtBoxName
        }
        else if(e.KeyCode == Keys.Down)
        {
            //switch to TxtBoxNote
        }
    }
    private void TxtBoxNote_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
        {
            AssignNewPerson();
        }
        else if (e.KeyCode == Keys.Up)
        {
            //switch to TxtBoxDebt
        }
        else if (e.KeyCode == Keys.Down)
        {
            //switch to BtnAssign
        }
    }
dw1jzc5e

dw1jzc5e1#

我认为您正在寻找Focus()方法,例如:

TxtBoxDebt.Focus();

相关问题