Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I change selected textBox in windowsForms app

I want users to be able to travel between textboxes and to a button by clicking Keys.Enter, Keys.Up, Keys.Down. Is there a way like this.SelectedItem = TxtBoxName or something?

    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
        }
    }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I think you are looking for the Focus() method, for example:

TxtBoxDebt.Focus();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading