/// <summary> /// 在需要绘制时发生 /// </summary> protected override void OnPaint(PaintEventArgs e) { if (_clientBounds != ClientRectangle || _updatePositionsOnDraw) { _clientBounds = ClientRectangle; _updatePositionsOnDraw = false; UpdatePositions(e.Graphics, false); } OnPaintPanelBackground(e); if (CaptionButtonsCount > 0) { OnDrawCaptionButtons(_captionButtonsBounds, e.Graphics); } DrawRoundBorder(e); int buttonsCount = _buttons.Count; if (buttonsCount == 1 && ShowOneTabButton == false) { buttonsCount = 0; } if (buttonsCount > 0) { DrawButtonsLine(e); RectangleF clip = e.Graphics.ClipBounds; e.Graphics.SetClip(_buttonsPanelBounds); for (int index = buttonsCount - 1; index >= 0; index--) { if (index != SelectedIndex) { _buttons[index].Draw(ButtonsRenderer, false, Font, e.Graphics); } } _buttons[SelectedIndex].Draw(ButtonsRenderer, true, Font, e.Graphics); e.Graphics.SetClip(clip); } if (_hasScrolls && buttonsCount > 1) { UnitButtonState stateBack = UnitButtonState.Normal; UnitButtonState stateNext = UnitButtonState.Normal; if (_firstShownButtonIndex == 0) { stateBack = UnitButtonState.Disabled; } else if (IsMouseDownInScrollBackButton) { stateBack = UnitButtonState.Pressed | UnitButtonState.UnderMouseCursor; } else if (IsMouseOverScrollBackButton) { stateBack = UnitButtonState.UnderMouseCursor; } else if (IsMouseDownInScrollNextButton) { stateNext = UnitButtonState.Pressed | UnitButtonState.UnderMouseCursor; } else if (IsMouseOverScrollNextButton) { stateNext = UnitButtonState.UnderMouseCursor; } if (_canScrollNext == false) { stateNext = UnitButtonState.Disabled; } ButtonsRenderer.DrawScrollBackButton(_scrollBackBounds, stateBack, e.Graphics); ButtonsRenderer.DrawScrollNextButton(_scrollNextBounds, stateNext, e.Graphics); } base.OnPaint(e); }
/// <summary> /// 绘制下一个滚动按钮 /// </summary> /// <param name="bounds">按钮边界</param> /// <param name="state">按钮状态标识符</param> /// <param name="graphics">绘画对象</param> public abstract void DrawScrollNextButton(Rectangle bounds, UnitButtonState state, Graphics graphics);
public override void DrawScrollNextButton(Rectangle bounds, UnitButtonState state, Graphics graphics) { int x1 = bounds.Left + 5; int y1 = bounds.Top + bounds.Height / 2 + 2; int x2 = x1 - 5; int y2 = y1 - 5; int x3 = x2; int y3 = y1 + 4; using (GraphicsPath arrowHeadPath = new GraphicsPath()) { arrowHeadPath.AddLine(x1, y1 - 1, x2, y2 - 1); arrowHeadPath.AddLine(x2, y2 - 1, x3, y3 + 1); arrowHeadPath.CloseFigure(); switch (state) { case UnitButtonState.Normal: graphics.FillPath(Brushes.LightSteelBlue, arrowHeadPath); graphics.DrawLine(Pens.DarkBlue, x1, y1 - 1, x2, y2 - 1); graphics.DrawLine(Pens.DarkBlue, x2, y2 - 1, x3, y3 + 1); graphics.DrawLine(Pens.White, x3, y3 + 1, x1, y1 + 1); break; case UnitButtonState.Focus: graphics.FillPath(Brushes.LightGreen, arrowHeadPath); graphics.DrawLine(Pens.Blue, x1, y1 - 1, x2, y2 - 1); graphics.DrawLine(Pens.Blue, x2, y2 - 1, x3, y3 + 1); graphics.DrawLine(Pens.White, x3, y3 + 1, x1, y1 + 1); break; case UnitButtonState.Pressed: graphics.FillPath(Brushes.LightSteelBlue, arrowHeadPath); graphics.DrawLine(Pens.DarkBlue, x3, y3 + 1, x1, y1 + 1); graphics.DrawLine(Pens.DarkBlue, x2, y2 - 1, x3, y3 + 1); graphics.DrawLine(Pens.WhiteSmoke, x1, y1 - 1, x2, y2 - 1); break; case UnitButtonState.UnderMouseCursor: graphics.FillPath(Brushes.LightSteelBlue, arrowHeadPath); graphics.DrawLine(Pens.Blue, x1, y1 - 1, x2, y2 - 1); graphics.DrawLine(Pens.Blue, x2, y2 - 1, x3, y3 + 1); graphics.DrawLine(Pens.White, x3, y3 + 1, x1, y1 + 1); break; case UnitButtonState.Disabled: graphics.FillPath(Brushes.Gray, arrowHeadPath); graphics.DrawLine(Pens.DarkGray, x1, y1 - 1, x2, y2 - 1); graphics.DrawLine(Pens.DarkGray, x2, y2 - 1, x3, y3 + 1); graphics.DrawLine(Pens.White, x3, y3 + 1, x1, y1 + 1); break; } } }