Centering a Form

  • Thread starter Thread starter peter hansen
  • Start date Start date
P

peter hansen

In old Visual BASIC 6-days it was possible to set the Left and Top-property
of a Form and put it into the center of the screen by using the Screen.Left,
Screen.Width, Top and Height.

Where do I find those old properties in VB 2003.NET

// Peter
 
me.Left, me.Top, etc.

You can also set the startup position of the form to centerscreen, or if you
are using showdialog, you can use the centerowner.
 
Hi peter

me.StartPosition = FormStartPosition.CenterScreen

I think this is even easier?

Cor
 
* "peter hansen said:
In old Visual BASIC 6-days it was possible to set the Left and Top-property
of a Form and put it into the center of the screen by using the Screen.Left,
Screen.Width, Top and Height.

Set its 'StartPosition' property to 'CenterScreen' or call the form's
'CenterToScreen' method.
 
-----Original Message-----
In old Visual BASIC 6-days it was possible to set the Left and Top-property
of a Form and put it into the center of the screen by using the Screen.Left,
Screen.Width, Top and Height.

Where do I find those old properties in VB 2003.NET

// Peter


.

Try This


CenterForm(ME)
''''''''''''''''''''''''

Sub CenterForm(ByVal TheForm As Form)
' Centers the form on the screen.
Dim RecForm As Rectangle = Screen.GetBounds
(TheForm)
TheForm.Left = CInt((RecForm.Width -
TheForm.Width) / 2)
TheForm.Top = CInt((RecForm.Height -
TheForm.Height) / 2)
End Sub
 
* "Marc said:
Try This


CenterForm(ME)
''''''''''''''''''''''''

Sub CenterForm(ByVal TheForm As Form)
' Centers the form on the screen.
Dim RecForm As Rectangle = Screen.GetBounds
(TheForm)
TheForm.Left = CInt((RecForm.Width -
TheForm.Width) / 2)
TheForm.Top = CInt((RecForm.Height -
TheForm.Height) / 2)
End Sub

Why do that if the functionality is already built in?

;-)
 
Back
Top