public override void SetBounds(System.Drawing.Rectangle bounds) { base.SetBounds(bounds); #region Assign control buttons bounds if (ScrollType != ListScrollType.Scrollbar) { #region Custom Buttons int cbtns = 3; // 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); } _thumbBounds.Location = Point.Empty; #endregion } else { #region Scrollbar int bwidth = ThumbBounds.Width; int bheight = ThumbBounds.Width; _buttonUpBounds = Rectangle.FromLTRB(bounds.Right - bwidth, bounds.Top + 1, bounds.Right, bounds.Top + bheight + 1); _buttonDownBounds = Rectangle.FromLTRB(_buttonUpBounds.Left, bounds.Bottom - bheight, bounds.Right, bounds.Bottom); _buttonDropDownBounds = Rectangle.Empty; _thumbBounds.X = _buttonUpBounds.Left; #endregion } _contentBounds = Rectangle.FromLTRB(bounds.Left + 1, bounds.Top + 1, _buttonUpBounds.Left - 1, bounds.Bottom - 1); #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 = curTop; // int.MinValue; int iniTop = curTop; 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; } 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; } //Kevin - The bottom row of buttons were always getting cropped off a tiny bit maxBottom += 1; #endregion #region Adjust thumb size double contentHeight = maxBottom - iniTop; double viewHeight = ContentBounds.Height; if (contentHeight > viewHeight && contentHeight != 0) { double viewPercent = viewHeight / contentHeight; double availHeight = ButtonDownBounds.Top - ButtonUpBounds.Bottom; double thumbHeight = Math.Ceiling(viewPercent * availHeight); if (thumbHeight < 30) { if (availHeight >= 30) { thumbHeight = 30; } else { thumbHeight = availHeight; } } _thumbBounds.Height = Convert.ToInt32(thumbHeight); fullContentBounds = Rectangle.FromLTRB(ContentBounds.Left, iniTop, ContentBounds.Right, maxBottom); _scrollBarEnabled = true && !NoScroll; UpdateThumbPos(); } else { _scrollBarEnabled = false; } #endregion }
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 }