Ali
Ali

Reputation: 3469

How to prevent focusing Controls in UserControl

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?

Upvotes: 0

Views: 303

Answers (1)

Ali
Ali

Reputation: 3469

Use:

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

Instead Of:

UserControl.ProcessTabKey();

Will Solve Problem.

Upvotes: 1

Related Questions