Home > OS >  How to switch to a next "Entity" (Example TB or MaskedTB) on the form with a specific key
How to switch to a next "Entity" (Example TB or MaskedTB) on the form with a specific key

Time:01-24

I am trying to find a solution to replicate what tab does when you are focused on a specific TextBox or MaskedTextBox, I already set my TabIndexs in order through Properties in VS

FormaNalaza is a form

    private void FormaNalaza_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
        {
            //Switch to the next TabIndex Entity
        }
    }

This was my solution but I couldn't figure out how to change the focus to the next Entity in the form

I tried SelectNextControl(The starting Entity, 1, 0, 0, 0)

CodePudding user response:

Simple Implementation:

private void FormaNalaza_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        //Switch to the next TabIndex Entity
        SendKeys.Send("{Tab}");
    }
}

Tab Order

enter image description here

Output:

enter image description here

CodePudding user response:

The tab key does this automatically, so if you are ok with pressing tab instead of enter, you can do that. Changing the TabIndex property of your entities will change the order in which tab will switch between them.

  •  Tags:  
  • Related