Form.Show () slightly moves the position position

I have an application with a main form that acts as a kind of frame and an area inside the main form, where I open other forms. These forms should not ever close when a new one opens. I use this code to open it for the first time:

frm.WindowState = FormWindowState.Maximized; frm.BringToFront(); 

And then, if another form opens on top of this, and I need to show it again, I just use:

 frm.Show(); 

The problem is when I open the form, when it is first positioned, and the borders align beautifully. When I use frm.Show () to return it, it moves slightly left and down. Any clue why?

+2
c # winforms
source share
2 answers

You must set the StartPosition property to "manual" in the form properties window

or

frm.StartPosition = System.Windows.Forms.FormStartPosition.Manual;

+6
source share

From your explanation, I understand that you are using the parent form to contain the MDI child forms (correct me if I am wrong)

When a new MDI child form is shown, it is placed so that the child forms are in a cascade, that is, each child form is in the same position as the previous one, plus an offset. When you hide the child form and show it again, the MDI container probably thinks it is a new child form and it fits accordingly ...

I think you need to save the location of the child form before hiding it so that you can restore it when you show it again

+2
source share

All Articles