Ejemplo n.º 1
0
        /// <summary>
        /// Override the resize event to force a re-layout of the content.
        /// </summary>
        /// <param name="e">Resize event arguments</param>
        protected override void OnResize(EventArgs e)
        {
            if (!_inLayout)
            {
                int index = 0;
                while (index < Controls.Count)
                {
                    CanvasItem item = (CanvasItem)Controls[index];
                    item.SetBounds(0, 0, ClientRectangle.Width, 0, BoundsSpecified.Width);
                    ++index;
                }

                LayoutControls(null);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Layout all the canvas items from either the given item or from
        /// the start if null is specified.
        /// </summary>
        public void LayoutControls(CanvasItem firstControl)
        {
            if (!_inLayout)
            {
                bool layoutAll = (firstControl == null);

                _inLayout = true;
                int index = (layoutAll) ? 0 : Controls.IndexOf(firstControl);
                if (index >= 0)
                {
                    Point point;

                    if (index > 0)
                    {
                        point    = Controls[index - 1].Location;
                        point.Y += Controls[index - 1].Height;
                    }
                    else
                    {
                        point = AutoScrollPosition;
                    }

                    int topOffset = Math.Abs(point.Y);
                    int yCount    = 0;

                    while (index < Controls.Count && (layoutAll || yCount < ClientRectangle.Bottom * 2))
                    {
                        CanvasItem      item  = (CanvasItem)Controls[index];
                        BoundsSpecified flags = BoundsSpecified.None;

                        if (item.Bounds.X != point.X)
                        {
                            flags |= BoundsSpecified.X;
                        }
                        if (item.Bounds.Y != point.Y)
                        {
                            flags |= BoundsSpecified.Y;
                        }
                        if (item.Bounds.Width != ClientRectangle.Width)
                        {
                            flags |= BoundsSpecified.Width;
                        }
                        if (item.Bounds.Height != item.Height)
                        {
                            flags |= BoundsSpecified.Height;
                        }
                        item.SetBounds(point.X, point.Y, ClientRectangle.Width, item.Height, flags);

                        point.Y += item.Height;
                        yCount  += item.Height - topOffset;

                        topOffset = 0;
                        ++index;
                    }

                    // If the collection changed then we need to update the virtual display
                    // rectangle bounds too.
                    if (_displayRectUpdate)
                    {
                        while (index < Controls.Count)
                        {
                            CanvasItem item = (CanvasItem)Controls[index++];
                            point.Y += item.Height;
                        }
                        AutoScrollMinSize = new Size(DisplayRectangle.Width, point.Y);

                        _displayRectUpdate = false;
                    }
                }
                _inLayout = false;
            }
        }