Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
620
Set Ultragroupbox header height
posted

Hi 

 

How do I set the Ultragroupbox header height ?

 

Thanks in advance

Parents
No Data
Reply
  • 37774
    Suggested Answer
    posted

    There is no way built into the control to increase the size of the header without increasing the size of the font.  You might be able to get this to work using a CreationFilter, but I think that you will encounter a problem with this due to the fact that the docking/anchoring logic is not really based on the UIElements, but rather on the size of the control itself. 

    I was able to put together a sample that seems to handle these problems, though you will have to account for different border styles yourself.  Note that I combine both a CreationFilter as well as deriving my own class from UltraGroupBox so that I can override the DisplayRectangle property, which is used to position child controls.

    public class MyGroupBox : UltraGroupBox
    {
        private Rectangle contentRect = Rectangle.Empty;

        public MyGroupBox()
            : base()
        {
            this.CreationFilter = new GroupBoxCreationFilter(this);
        }

        public Rectangle ContentRect
        {
            get { return this.contentRect; }
            set
            {
                if (this.contentRect == value)
                    return;

                // The CreationFilter repositions the child elements, but doesn't
                // actually update the layout.  Therefore, if we get a new content
                // rect, re-perform the layout to resize controls.
                this.contentRect = value;
                this.PerformLayout();
            }
        }

        public override Rectangle DisplayRectangle
        {
            get
            {
                if (this.contentRect != Rectangle.Empty)
                    return this.contentRect;

                return base.DisplayRectangle;
            }
        }

        private class GroupBoxCreationFilter : IUIElementCreationFilter
        {
            private const int HeaderHeight = 50;
            private MyGroupBox groupBox;
            private Rectangle lastHeaderRect = Rectangle.Empty;

            public GroupBoxCreationFilter(MyGroupBox groupBox)
            {
                this.groupBox = groupBox;
            }

            public void AfterCreateChildElements(UIElement parent)
            {
            }

            public bool BeforeCreateChildElements(UIElement parent)
            {
                if (parent is Infragistics.Win.Misc.GroupBoxHeaderUIElement)
                {
                    parent.Rect = new Rectangle(
                        parent.Rect.Left,
                        parent.Rect.Top,
                        parent.Rect.Width,
                        50);

                    this.lastHeaderRect = parent.Rect;
                }
                else if (parent is Infragistics.Win.Misc.GroupBoxContentAreaUIElement)
                {
                    parent.Rect = new Rectangle(
                        parent.Rect.Left,
                        this.lastHeaderRect.Bottom,
                        parent.Rect.Width,
                        parent.Control.Size.Height - this.lastHeaderRect.Bottom);

                    Rectangle contentRect = parent.Rect;
                    contentRect.Inflate(-2, -2); // Shrink the rect so we can see the borders
                    this.groupBox.ContentRect = contentRect;
                }
                return false;
            }
        }
    }

    -Matt

Children
No Data