Jose M.
Jose M.

Reputation: 2330

Opening winforms in the same screen

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?

Upvotes: 4

Views: 3697

Answers (2)

John Peake
John Peake

Reputation: 1

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)

Upvotes: 0

Mark Hall
Mark Hall

Reputation: 54532

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

Upvotes: 5

Related Questions