Form's Position changed after Show & Hide
-
Hi, I use form.Hide() to hide a form, and use form.Show() to bring it back. However, I found that the form's position is changed. How did this happen? I didn't recreate this form, just hide and show again. How can I keep it as where it was? Thanks!
I found this from msdn about "Form.WindowState Property" Before a form is displayed, the WindowState property is always set to FormWindowState.Normal, regardless of its initial setting. This is reflected in the Height, Left, Top, and Width property settings. If a form is hidden after it has been shown, these properties reflect the previous state until the form is shown again, regardless of any changes made to the WindowState property. I think this is the reason, my form keeps changing position. But How can I keep it stay where it was? Thanks in advance.
-
I found this from msdn about "Form.WindowState Property" Before a form is displayed, the WindowState property is always set to FormWindowState.Normal, regardless of its initial setting. This is reflected in the Height, Left, Top, and Width property settings. If a form is hidden after it has been shown, these properties reflect the previous state until the form is shown again, regardless of any changes made to the WindowState property. I think this is the reason, my form keeps changing position. But How can I keep it stay where it was? Thanks in advance.
You could set some variables to the co-ordinaets of your form when you hide it, then when you show it, re-set the form's position to those variables. i.e.
Point loc = this.Location; this.Hide();
//Showingthis.Show(); this.Location = loc;
Not a great solution but would work till you can get a better one. Kev Robert E. Lee's Truce Judgement comes from experience; experience comes from poor judgement. -
You could set some variables to the co-ordinaets of your form when you hide it, then when you show it, re-set the form's position to those variables. i.e.
Point loc = this.Location; this.Hide();
//Showingthis.Show(); this.Location = loc;
Not a great solution but would work till you can get a better one. Kev Robert E. Lee's Truce Judgement comes from experience; experience comes from poor judgement.