0

I have a User-Control with 2 Textbox and 1 Button, Something like below:

my UserControl

When I press the button a form show and when the form closed I want to leave focus from User-Control and next control on the Form got focus, I write this code for this issue:

private void Btn_Select_Click(object sender, EventArgs e)
{
    if (t.ShowDialog() == DialogResult.OK)
        ProcessTabKey(true);
}

I excepted that next control on the Parent Form got focus BUT the textbox on UserControl got focus, I change the TabStop property to false for 2 textbox but still have the problem.

Could anyone know how I solve this problem?

Community
  • 1
  • 1
Ali
  • 3,373
  • 5
  • 42
  • 54
  • 1
    UserControl.ProcessTabKey() just doesn't do what you hope it does. You'll have better odds with this.FindForm().SelectNextControl(this, true, true, true, true); The only truly correct way is to leave it up to the form to decide which control should get the focus next, raise an event. – Hans Passant Feb 21 '18 at 14:09

1 Answers1

1

Use:

this.FindForm().SelectNextControl(this, true, true, true, true); 

Instead Of:

UserControl.ProcessTabKey();

Will Solve Problem.

Ali
  • 3,373
  • 5
  • 42
  • 54