4

I have an application with multiple win forms. I have noticed is that if the user has multiple screen displays and changes the application to one screen, the other forms that are called by other buttons, will open in the main display and not where my main application or form is.

How can I change this?

Imad Alazani
  • 6,688
  • 7
  • 36
  • 58
Jose M.
  • 2,242
  • 8
  • 44
  • 66
  • Try checking `Screen` class (http://msdn.microsoft.com/en-us/library/system.windows.forms.screen.aspx) and look at `PrimaryScreen` property. So if it is Primary screen make it visible. Is this what you are looking for ? – NeverHopeless Aug 05 '13 at 03:45

1 Answers1

4

You can use the Form.CenterToParent Method on your Forms, they will then open up centered on your the creating Form, Or you can use the Screen Class to get the Bounds of the Display that your Main application is running on, then pass it to your created forms.

Edit:

On second thought assigning the Owner might just be enough, I don't have a dual monitor computer booted up at this time to test though

Dim frm As Form1 = New Form1()
frm.Owner = Me
frm.CenterToParent()
frm.Show()

Edit

Just had a chance to check it out. It was as I thought assigning the Owner to the new Form or using the Form.Show(IWin32Window) will open the new Form on the same screen as the originating Form.

frm.Show(Me)


Looks like the CenterToParent property is protected now. According to the MSDN link

Do not call the CenterToParent method directly from your code. Instead, set the StartPosition property to CenterParent. If the form or dialog is top-level, then CenterToParent centers the form with respect to the screen or desktop

Mark Hall
  • 53,938
  • 9
  • 94
  • 111
  • Note: just setting Owner was not sufficient in my tests. And `Form.CenterToParent()` is protected so you cannot just call it directly. – RBarryYoung Feb 27 '18 at 16:15
  • 2
    Looks like they changed it in the newer frameworks. According to the link I have in my answer it says to use Form.SetPosition with CenterParent enumeration. – Mark Hall Feb 27 '18 at 16:39
  • 2
    However, bizarrely, using only `frm.Show(Me)` *did* work for me. Weird. – RBarryYoung Feb 27 '18 at 16:44
  • 1
    None of the options are working for me, after moving the owner from one screen to another. The new form will popup on the screen where the owner was created. – Good Night Nerd Pride Oct 18 '20 at 10:14
  • This way worked for me though: https://stackoverflow.com/questions/32411839/create-new-form-on-same-screen-position/32411919 – Good Night Nerd Pride Oct 18 '20 at 11:05