Results 1 to 4 of 4

Thread: [RESOLVED] Vb6 - center a control in the form

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2006
    Location
    Paris
    Posts
    301

    Resolved [RESOLVED] Vb6 - center a control in the form

    Hi
    To grafically center a control inside a form I came up with this simple formula:
    let's say I want to center a label:

    label.left=(me.width / 2) - (label.width / 2 )
    label.top = (me.height / 2) - (label.height / 2)

    I tried this several times with different controls and it works perfectly for
    the horizontal centering BUT the vertical place is always clearly not where it should be. With this formula it ends up near the bottom of the page almost.

    What am I doing wrong ?

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Vb6 - center a control in the form

    Me.Height includes the Caption bar height, try ScaleHeight instead:
    Code:
        Label1.Left = (Me.ScaleWidth / 2) - (Label1.Width / 2)
        Label1.Top = (Me.ScaleHeight / 2) - (Label1.Height / 2)

  3. #3
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Vb6 - center a control in the form

    you can do it this way as well

    Code:
    Control.Left=(me.scalewidth-Control.width)/2
    Control.Hieght=(me.scaleheight-control.height)/2

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2006
    Location
    Paris
    Posts
    301

    Re: Vb6 - center a control in the form

    Thanks guys,
    Scaleheight is the solution.

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