Results 1 to 3 of 3

Thread: [RESOLVED] Label not centering on form

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Location
    Manchester, UK
    Posts
    180

    Resolved [RESOLVED] Label not centering on form

    Code:
    Private Sub Form_Load()
    Me.WindowState = 2
    With Label1
            .Move (ScaleWidth - .Width) / 2, (ScaleHeight - .Height) / 2
        End With
    End Sub
    Can anybody suggest why the label is not centering on the form using this code?


    "And then one day you find, ten years have got behind you.
    No one told you when to run, you missed the starting gun."

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Label not centering on form

    The form may not be resized yet. Try adding a DoEvents after setting the window state.

    Tip: Add the label positioning to the form's Resize event vs the Load event. If you do, also check to ensure the WindowState<>vbMinimized before repositioning the label, because you will get an error positioning controls while form is minimized.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Location
    Manchester, UK
    Posts
    180

    Re: Label not centering on form

    Quote Originally Posted by LaVolpe View Post
    The form may not be resized yet. Try adding a DoEvents after setting the window state.

    Tip: Add the label positioning to the form's Resize event vs the Load event. If you do, also check to ensure the WindowState<>vbMinimized before repositioning the label, because you will get an error positioning controls while form is minimized.
    I added the label positioning to the form's resize event and that worked, thanks....


    "And then one day you find, ten years have got behind you.
    No one told you when to run, you missed the starting gun."

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