Scale tiles on form resize

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

    Posted 23 Jan 2013 Link to this post

    Is there a way to do this?
  2. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 25 Jan 2013 Link to this post

    Hi Andre,

    The default behavior of RadPanorama is to use the CellSize property to control tile width and height. You can sync this property with RadPanorama size by handling its SizeChanged even like demonstrated below:
    Size originalSize;
    Size originalCellSize;
     
    originalSize = panorama.Size;
    originalCellSize = panorama.CellSize;
    panorama.SizeChanged += new EventHandler(panorama_SizeChanged);
     
    void panorama_SizeChanged(object sender, EventArgs e)
    {
        SizeF delta = new SizeF((float)panorama.Size.Width / (float)originalSize.Width, (float)panorama.Size.Height / (float)originalSize.Height);
        panorama.PanoramaElement.CellSize = new System.Drawing.Size(
            (int)(originalCellSize.Width * delta.Width),
            (int)(originalCellSize.Height * delta.Height));
    }

    I hope this helps.
     
    Kind regards,
    Jack
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Andre
    Andre avatar
    30 posts
    Member since:
    Dec 2012

    Posted 25 Jan 2013 Link to this post

    Thanks, the above is what i ended up doing originally. It got a little crazy when the user was allowed to reposition things. I've ended up simply centering the control in the window at a fixed size.

    Ideally i would like to have the controls width to resize, and have the groups centered. Is there a way to automatically center the groups?
  5. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 28 Jan 2013 Link to this post

    Hi Andre,

    The solution from my previous post works when there are no groups in RadPanorama. Consider the following code which works when using groups:
    void panorama_SizeChanged(object sender, EventArgs e)
    {
        SizeF delta = new SizeF((float)panorama.Size.Width / (float)originalSize.Width, (float)panorama.Size.Height / (float)originalSize.Height);
        foreach (TileGroupElement tileGroup in panorama.Groups)
        {
            tileGroup.CellSize = new System.Drawing.Size(
                (int)(originalCellSize.Width * delta.Width),
                (int)(originalCellSize.Height * delta.Height));
        }
    }

    The same applies on the case when centering tiles. The difference is that you should arrange GroupLayout instead of TileLayout. Consider the code below:
    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(0,
                (finalSize.Height - this.GroupLayout.DesiredSize.Height) / 2, this.GroupLayout.DesiredSize.Width, this.GroupLayout.DesiredSize.Height));
                 
     
            return finalSize;
        }
    }

    I hope this helps.
     
    Regards,
    Jack
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Back to Top