Recipe 4.14. Centering a Form


Problem

You want a form to be in the center of the display when it first appears.

Solution

Set the form's StartPosition property to CenterScreen.

Discussion

That was easy, but there may be cases where you need to set this property to Manual, but you still want the form to appear centered sometimes. To accomplish this, add the following code to the Load event handler for your form:

 Me.Location = New Point(( _    Screen.PrimaryScreen.Bounds.Width - Me.Width) / 2, _    (Screen.PrimaryScreen.Bounds.Height - Me.Height) / 2) 




Visual Basic 2005 Cookbook(c) Solutions for VB 2005 Programmers
Visual Basic 2005 Cookbook: Solutions for VB 2005 Programmers (Cookbooks (OReilly))
ISBN: 0596101775
EAN: 2147483647
Year: 2006
Pages: 400

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net