简体   繁体   中英

Prevent windows form from moving across screen when another is opened

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.

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);

将窗体的StartPositionWindowsDefaultLocation更改为manual,然后在构造函数中设置Location

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM