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?

1
  • Try checking Screen class (msdn.microsoft.com/en-us/library/…) and look at PrimaryScreen property. So if it is Primary screen make it visible. Is this what you are looking for ? Commented Aug 5, 2013 at 3:45

2 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

5 Comments

Note: just setting Owner was not sufficient in my tests. And Form.CenterToParent() is protected so you cannot just call it directly.
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.
However, bizarrely, using only frm.Show(Me) did work for me. Weird.
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.
This way worked for me though: stackoverflow.com/questions/32411839/…
0

I solved by using point. I have two forms and I always want the second form to open beside the first. I read the Point of the Form1 and substracted the width of Form2 from Point X value.

Dim P As New Point P = Form1.Location Me.Location = New Point(P.X - 400, P.Y) 

1 Comment

Sigh. You do know that when you use New as you declare a variable, and then immediately assign a different object to the variable, without ever using the New object, you're wasting memory and GC time, right? You allocated a whole new object just to throw it away on the very next line of code. It's slightly better here because Point is a struct, and even for classes I suspect the compiler optimizes the mistake away, but it still screams, "This person doesn't really know the difference between a variable, a reference, and an object."

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.