Results 1 to 5 of 5

Thread: [RESOLVED] center a smaller form over the calling form

  1. #1

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Resolved [RESOLVED] center a smaller form over the calling form

    i am trying to center a smaller form over the calling form
    like this:
    code in the smaller form
    Public Sub CenterMe(frm As Form)
    Me.Left = frm.ScaleWidth / 2 - Me.Width / 2
    Me.Top = frm.ScaleHeight / 2 - Me.Height / 2

    Me.Show
    End Sub

    Calling it like this:
    form1.CenterMe frmKeno

    The smaller form is too far left and not high enough. (not centered)
    what am i doing wrong ?
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  2. #2
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    804

    Re: center a smaller form over the calling form

    1. You are not taking into account the main form's Left & Top properties
    2. Not sure why you're using width for one form and scalewidth for the other, etc.

    Code:
    Private Sub CenterMe(Main As Form)
     Left = Main.Left + (Abs(Main.ScaleWidth - ScaleWidth)) \ 2
     Top = Main.Top + (Abs(Main.ScaleHeight - ScaleHeight)) \ 2
    End Sub

  3. #3

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: center a smaller form over the calling form

    thanks that fixed the issue
    Not sure why you're using width for one form and scalewidth for the other, etc.
    i was trying different things
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  4. #4
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: [RESOLVED] center a smaller form over the calling form

    It can also be done by setting the StartUpPosition property to "1 - CenterOwner" on the form you are trying to center and then from the other form call it using the syntax
    Form2.Show , Me

    No calculations required.

  5. #5

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: [RESOLVED] center a smaller form over the calling form

    Good idea
    Thanks
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

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