1

Resolved

GroupBox client container fix

description

When adding controls to the GroupBox control that are anchored to all sides (Anchor.All) and fully fill up the groupbox client area, the control inside the groupbox overlaps the groupbox text header. I have included a fix below.
 
Place the fallowing code in the GroupBox.cs file.
 
    private void AdjustClientMargins()
    {
        SkinLayer layer = this.type == GroupBoxType.Normal ? this.Skin.Layers["Control"] : this.Skin.Layers["Flat"];
        SpriteFont font = (layer.Text != null && layer.Text.Font != null) ? layer.Text.Font.Resource : null;
        Vector2 size = font.MeasureString(this.Text);
        var cm = this.ClientMargins;
        cm.Top = string.IsNullOrWhiteSpace( this.Text) ? this.ClientTop : (int)size.Y;
        this.ClientMargins = new Margins(cm.Left, cm.Top, cm.Right, cm.Bottom);
    }

    protected internal override void OnSkinChanged(EventArgs e)
    {
        base.OnSkinChanged(e);
        AdjustClientMargins();
    }
 
    protected override void OnTextChanged(EventArgs e)
    {
        base.OnTextChanged(e);
        AdjustClientMargins();
    }
 
This code will prevent any child controls added to the groupbox from overlapping the groupbox text header.

comments

grimston wrote Apr 6, 2013 at 6:19 AM

Fixed as of changeset 31568

wrote May 16, 2013 at 10:22 AM

wrote May 16, 2013 at 10:22 AM

wrote Jun 14, 2013 at 7:19 AM