Exemple #1
0
        public override void SetBounds(System.Drawing.Rectangle bounds)
        {
            base.SetBounds(bounds);

            #region Assign control buttons bounds

            int cbtns        = Canvas is RibbonDropDown ? 2 : 3;
            int buttonHeight = bounds.Height / cbtns;
            int buttonWidth  = _controlButtonsWidth;


            _buttonUpBounds = Rectangle.FromLTRB(bounds.Right - buttonWidth,
                                                 bounds.Top, bounds.Right, bounds.Top + buttonHeight);

            _buttonDownBounds = Rectangle.FromLTRB(_buttonUpBounds.Left, _buttonUpBounds.Bottom,
                                                   bounds.Right, _buttonUpBounds.Bottom + buttonHeight);


            if (cbtns == 2)
            {
                _buttonDropDownBounds = Rectangle.Empty;
            }
            else
            {
                _buttonDropDownBounds = Rectangle.FromLTRB(_buttonDownBounds.Left, _buttonDownBounds.Bottom,
                                                           bounds.Right, bounds.Bottom + 1);
            }

            _contentBounds = Rectangle.FromLTRB(bounds.Left, bounds.Top, _buttonUpBounds.Left, bounds.Bottom);

            #endregion

            #region Assign buttons regions

            _buttonUpEnabled = _offset < 0;
            if (!_buttonUpEnabled)
            {
                _offset = 0;
            }
            _buttonDownEnabled = false;

            int curLeft   = ContentBounds.Left + 1;
            int curTop    = ContentBounds.Top + 1 + _offset;
            int maxBottom = int.MinValue;

            foreach (RibbonItem item in Buttons)
            {
                item.SetBounds(Rectangle.Empty);
            }

            for (int i = 0; i < Buttons.Count; i++)
            {
                RibbonButton button = Buttons[i] as RibbonButton; if (button == null)
                {
                    break;
                }

                if (curLeft + button.LastMeasuredSize.Width > ContentBounds.Right)
                {
                    curLeft = ContentBounds.Left + 1;
                    curTop  = maxBottom + 1;

                    if (curTop > ContentBounds.Bottom)
                    {
                        break;
                    }
                }

                button.SetBounds(new Rectangle(curLeft, curTop, button.LastMeasuredSize.Width, button.LastMeasuredSize.Height));

                curLeft   = button.Bounds.Right + 1;
                maxBottom = Math.Max(maxBottom, button.Bounds.Bottom);

                if (button.Bounds.Bottom > ContentBounds.Bottom)
                {
                    _buttonDownEnabled = true;
                }

                _jumpDownSize = button.Bounds.Height;
                _jumpUpSize   = button.Bounds.Height;
            }



            #endregion
        }