Results 1 to 2 of 2

Thread: Centering a form

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 1999
    Location
    Sydney,NSW,Australia
    Posts
    178

    Post

    OK l know about the Left and top commands and have used these successfully. Does anyone know how to take into account the task bar when positioning a form, so that the form is centered in the "available" window space. Thanks in advance

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Try this:

    Code:
    Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
    Private Const SM_CXFULLSCREEN = 16
    Private Const SM_CYFULLSCREEN = 17
    Public Sub CenterForm(pForm As Form)
        Dim lngLeft As Long, lngTop As Long
        
        lngLeft = (Screen.TwipsPerPixelX * (GetSystemMetrics(SM_CXFULLSCREEN) / 2)) - (pForm.Width / 2)
        lngTop = (Screen.TwipsPerPixelY * (GetSystemMetrics(SM_CYFULLSCREEN) / 2)) - (pForm.Height / 2)
        pForm.Move lngLeft, lngTop
    End Sub
    Usage: CenterForm Form
    Example: CenterForm Me

    ------------------

    Serge

    Senior Programmer Analyst
    [email protected]
    [email protected]
    ICQ#: 51055819

    [This message has been edited by Serge (edited 02-22-2000).]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width