Reputation: 6518
I have a winforms with multiple windows.I show the window by using
myform.show();
Currently the form's top bar (with the close and minimize button) is out of focus. I need it to be focused.
I tried
myform.Focus();
It does not work.
For Example this how the window looks now..
I need it to be like this
I need it to be focused (see the top bar) without user intervention of clicking on it.Please advice.
Upvotes: 0
Views: 60
Reputation: 749
Some other control is taking focus away from the form after you are calling myform.Focus();
To get around this, you can wait until the form (and hopefully most of your controls) have been loaded and shown on the form, and then call this.Focus();
In the Form.Shown() event handler call this.Focus();
For Example:
private void Form_Shown(object sender, EventArgs e)
{
this.Focus();
}
Upvotes: 1