dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Automatically align controls?

  1. #1
    Join Date
    Mar 2007
    Location
    Argentina
    Posts
    579

    Automatically align controls?

    I add a set of userControls to a groupbox.
    The groupbox is set to autosize = true, which is nice, since I need to not care about resizing the groupbox each time I add a new UserControl.

    I want to the added controls to align themselves whit equal vertical spacing.
    when I add a new control with
    Code:
    MyGroupBox.controls.add(MyNewUserControl)
    , then, to avoid all the UserControls to be overlapped in the top left, I need to do
    Code:
    with MyNewUserControl
        .Top = MyGroupBox.Padding.Top + .Padding.Top + (MyGroupBox.Controls.Count - 1) * .Size.Height
        .Left = MyGroupBox.Padding.Left + .Padding.Left
    end with
    The result is this: (after adding 3 controls)
    Obviously, is buggy:
    1-¿Why GroupBox Title overlaps with first UserControl?
    2-¿Why left margin (=MyGroupBox.Padding.Left + .Padding.Left) is different than AutoSize right margin?
    3-¿Why Autosized botton marging is so huge????
    Attached Images Attached Images  
    Last edited by Marraco; December 9th, 2008 at 07:00 AM. Reason: Deleted repeated dots
    [Vb.NET 2008 (ex Express)]

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Automatically align controls?

    You're trying to calculate exact numbers. Try using Padding.Bottom of the one above it to figure out the offset of each one.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Mar 2007
    Location
    Argentina
    Posts
    579

    Re: Automatically align controls?

    Quote Originally Posted by dglienna View Post
    You're trying to calculate exact numbers. Try using Padding.Bottom of the one above it to figure out the offset of each one.
    I have set the .Padding.All, and .Margin.All properties for any implied control, so all padding and margin are equal.

    Anyway, using the .Top and .Bottom instead of .All, makes the code more readable, and allowed me to see some bugs.

    Anyway, I changed the code to:

    Code:
    With MyNewUserControl
        .Top = MyGroupBox.Padding.Top + .Margin.Top + (MyGroupBox.Controls.Count - 1) * (.Margin.Top + .Margin.Bottom + .Size.Height)
        .Left = MyGroupBox.Padding.Left + .Margin.Left
    end With
    and it enhanced a bit, but still the Autosized bottom padding is bigger by no obvious reason.
    [Vb.NET 2008 (ex Express)]

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)