I have a form called Form1. Its set to startup-Position = Center but when executed it opens up somewhere else (At a random position evrytime).
I am working under Windows XP SP3 , using IDE Visual Studio - 2010. Please provide a workaround to this problem.
I have uploaded a sample project showing the above mentioned problem .
Download link:
http://www.6ybh-upload.com/vt5i4z1wz9pl/Light.zip
You have to set:
Form1.StartPosition = FormStartPosition.Manual
Here is a working sample:
Dim X As Integer = (Screen.PrimaryScreen.Bounds.Width - Me.Width) / 2
Dim Y As Integer = (Screen.PrimaryScreen.Bounds.Height - Me.Height) / 2
Me.StartPosition = FormStartPosition.Manual
Me.Location = New System.Drawing.Point(X, Y)
Here is the improved code based on comments by Hans Passant, (much better):
Dim mainScreen As Screen = Screen.FromPoint(Me.Location)
Dim X As Integer = (mainScreen.WorkingArea.Width - Me.Width) / 2 + mainScreen.WorkingArea.Left
Dim Y As Integer = (mainScreen.WorkingArea.Height - Me.Height) / 2 + mainScreen.WorkingArea.Top
Me.StartPosition = FormStartPosition.Manual
Me.Location = New System.Drawing.Point(X, Y)
Try to use this after resize the screen
Me.Size = New System.Drawing.Size(800, 436)
Me.CenterToScreen()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With