0

I am currently creating a windows forms app that switches through multiple forms to display different screens. One annoying thing is that when i switch from one form to the next, it moves the new form window down a little from the last one. EX:

form1 
     form2
          form3
               form4

I'm using .Hide() and .Show() to switch between the forms.

Is there a way to prevent this? As in, when i open form2, can I have it in the exact same spot that form1 was in?

I am using VS2017 if that helps at all.

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
Aric Peters
  • 111
  • 1
  • 2
  • 13

2 Answers2

0

There's no way to prevent this, as it's set by default to signal the user that he's opening up a new user. If it displayed directly on top, it might confuse the user, as he may think the previous window was destroyed/removed.

You can always set the location on your own though, using the following post: Setting form's location when calling Form.Show()

ConnectingForm CF = new ConnectingForm();
CF.StartPosition = FormStartPosition.CenterParent;
CF.Show(this);
Blue
  • 22,608
  • 7
  • 62
  • 92
0

Change the forms' StartPosition from WindowsDefaultLocation to manual, and set Location in the constructors.

  • 1
    Writing dpiAware code is pretty important today. Doing this in the constructor is pretty questionable, you can't know the real size of the window yet. One of the few good reasons to use the Load event, the StartPosition property does not matter. – Hans Passant Dec 01 '17 at 14:21