Results 1 to 10 of 10

Thread: center controls

  1. #1

    Thread Starter
    Member mafia_geek's Avatar
    Join Date
    Jan 2002
    Location
    California
    Posts
    45

    center controls

    how do i make a frame center on the form vertically and horizontally when the form is loaded?
    -mafia_geek-

    Condito, Ergo Sum

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    VB Code:
    1. Private Sub Form_Load()
    2.     Frame1.Move (Me.ScaleWidth - Frame1.Width) / 2, (Me.ScaleHeight - Frame1.Height) / 2
    3. End Sub
    -= a peet post =-

  3. #3
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    NY
    Posts
    497
    with Frame1

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

    end with
    end war
    stop greed

  4. #4
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    NY
    Posts
    497
    Ooops, peet may be more correct, as I forget that the scalemode is different for different controls (form vs. frame). Sorry.
    end war
    stop greed

  5. #5

    Thread Starter
    Member mafia_geek's Avatar
    Join Date
    Jan 2002
    Location
    California
    Posts
    45

    didn't work

    ok that works, you wouldn't happen to know how to size a form to the size of the screen would you?
    -mafia_geek-

    Condito, Ergo Sum

  6. #6
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    NY
    Posts
    497
    I just learned this today. Me.Windowstate = vbMaximized
    end war
    stop greed

  7. #7

    Thread Starter
    Member mafia_geek's Avatar
    Join Date
    Jan 2002
    Location
    California
    Posts
    45
    that wasn't what i was looking for vbmom, but i figured it out...
    peet's code wasn't doing much because the form wasn't sized to the size of the screen when it wasn't running. i just used:

    Code:
    Me.Width = Screen.Width
    Me.Height = Screen.Height

  8. #8
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    NY
    Posts
    497
    Don't know what you're doing, but you may be interested in using a timer to do things after the form loads.

    If you place a timer on your form with an interval of 1, set Me.WindowState = vbMaximized inside Form_Load, enable the timer as the last statement in the Form_Load, and put peet's code in the Timer's Timer event, that should work.
    end war
    stop greed

  9. #9

    Thread Starter
    Member mafia_geek's Avatar
    Join Date
    Jan 2002
    Location
    California
    Posts
    45
    I just needed something to make my form load as fullscreen with controls in the middle, but thanks anyway vbmom.
    -mafia_geek-

    Condito, Ergo Sum

  10. #10
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    Place Peet's code in the resize event. This way the frame still stays centered even if you resize the form by grabbing an edge and dragging it.

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