Center Groups

3 posts, 0 answers
  1. Andre
    Andre avatar
    30 posts
    Member since:
    Dec 2012

    Posted 24 Jan 2013 Link to this post

    Is there a quick way to center groups similar to the attached picture? Or do i have to do the calculations manually in the resize event?
  2. Andre
    Andre avatar
    30 posts
    Member since:
    Dec 2012

    Posted 25 Jan 2013 Link to this post

    I suppose i could do something along the lines of this (ignoring title and padding) in the resize event. But then i get into positioning each and every group. Also, is there not an easy way to calc the current size of a group.

      float newWidth = (radPanorama1.Width/2) - (tileGroupElement1.CellSize.Width * tileGroupElement1.ColumnsCount)/2;
     
    float newHeight = (radPanorama1.Height / 2) - (tileGroupElement1.CellSize.Height * tileGroupElement1.RowsCount) / 2;
     
               tileGroupElement1.PositionOffset = new SizeF(newWidth, newHeight);
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 29 Jan 2013 Link to this post

    Hello Andre,

    It is not easy to get the actual width of a group element because it is valid only when calling its parent element ArrangeOverride method. However, you can center groups both horizontally and vertically by using a custom RadPanoramaElement and overriding its ArrangeOverride method. Consider the following code:
    public class CustomPanorama : RadPanorama
    {
        public override string ThemeClassName
        {
            get
            {
                return typeof(RadPanorama).FullName;
            }
            set { }
        }
     
        protected override RadPanoramaElement CreatePanoramaElement()
        {
            return new CustomPanoramaElement();
        }
    }
     
    public class CustomPanoramaElement : RadPanoramaElement
    {
        protected override Type ThemeEffectiveType
        {
            get
            {
                return typeof(RadPanoramaElement);
            }
        }
     
        protected override SizeF ArrangeOverride(SizeF finalSize)
        {
            base.ArrangeOverride(finalSize);
     
            this.GroupLayout.Arrange(new RectangleF(
                (finalSize.Width - this.GroupLayout.DesiredSize.Width) / 2,
                (finalSize.Height - this.GroupLayout.DesiredSize.Height) / 2, this.GroupLayout.DesiredSize.Width, this.GroupLayout.DesiredSize.Height));
     
            return finalSize;
        }
    }

    If you have further questions, do not hesitate to contact me.
     
    All the best,
    Jack
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Back to Top