tags:

views:

279

answers:

2

I have an application with a main form that acts as a sort of frame and an area inside the main form where I open other forms. These forms must not be closed ever so when a new one is opened I use this code to open it for the first time:

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

And then if another form gets opened on top of that and I need to show it again I just use:

frm.Show();

The problem is when I open the form the first time its positioned perfectly and the borders line up nice. When I use frm.Show() to bring it back it moves it slightly to the left and down. Any clue why?

+1  A: 

From your explanations, I understand you're using a parent form to contain MDI child forms (correct me if I'm wrong)

When a new MDI child form is shown, it is placed so that child forms are in "cascade", i.e. each child form is at the same position of the previous one plus an offset. When you hide a child form and show it again, the MDI container probably considers that it's a new child form, and it places accordingly...

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

Thomas Levesque
So for all 20 or so forms I would need to save each's location and keep track? Or is there a way maybe to just say frm.Show() at this specific location?
novacara
You can track the location in the code of the child form itself... Even better, if you have different types of child form, create a base MdiChild class that handles this and inherit from it
Thomas Levesque
+1  A: 

You should set the StartPosition property to 'manual' in form properties window

or

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