HOWTO: Center a Form in the Windows CE Toolkit for VB5

ID: Q187687


The information in this article applies to:
  • Microsoft Windows CE Toolkit for Visual Basic 5.0


SUMMARY

This article describes how to center a form in the Windows CE Toolkit for Visual Basic 5.0 (VBCE).


MORE INFORMATION

To center a form in VBCE 5.0, use the Move method of the Form to reposition it on the screen.

The following example shows how to create a reusable routine that can be used to center any form in your project:

  1. Create a new Windows CE project in Visual Basic 5.0. Form1 is created by default.


  2. Size the form so that it will be somewhat smaller than the HPC screen.


  3. From the Project menu, click Add module.


  4. In the Module, add the following code:
    
          Public Sub CenterForm(Frm)
              'Do not try to use 'me' for the form reference (Frm).
              On Error Resume Next
              'Do not resize if Minimized or Maximized.
              If Frm.WindowState = 0 Then
                  Frm.Move (Screen.Width - Frm.Width) \ 2, _
                      (Screen.Height - Frm.Height) \ 2, _
                      Frm.Width, Frm.Height
              End If
    
          End Sub 


  5. In the Form_Load event of the form, call the CenterForm procedure as follows: (Unlike regular Visual Basic, the 'Me' keyword cannot be used to refer to the form.)
    
          Private Sub Form_Load()
              CenterForm Form1
          End Sub 


  6. Run the project, and note that when the form loads it is centered on the screen. Also note that VBCE 5.0 is unable to determine the height of the Windows CE taskbar. Therefore, the VBCE form is centered according to the metrics based on the full screen size.


Additional query words: vbce wce vbce5

Keywords : kbToolkit kbVBp500 kbWinCE100 kbGrpVB
Version : WINDOWS:
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: May 24, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.