/// <summary> /// 在鼠标向下时发生 /// </summary> protected override void OnMouseDown(MouseEventArgs e) { _isMouseDownInTabButton = false; _isMovingTabButton = false; if (IsMouseOverScrollBackButton) { IsMouseDownInScrollBackButton = true; ScrollBack(); } else if (IsMouseOverScrollNextButton) { IsMouseDownInScrollNextButton = true; ScrollNext(); } else if (_captionButtonsBounds.Contains(e.Location)) { int captionIndex = ButtonsRenderer.GetCaptionButtonIndex(_captionButtonsBounds, e.Location); OnMouseDownInCaptionButton(captionIndex, e); } else { int index = 0; UnitButton button = GetButtonFromPoint(e.Location, out index); if (button != null) { SelectedIndex = index; Invalidate(); _isMouseDownInTabButton = e.Button == MouseButtons.Left; OnMouseDownInTabButton(button); } } base.OnMouseDown(e); }
/// <summary> /// 当鼠标光标移到面板上时发生 /// </summary> protected override void OnMouseMove(MouseEventArgs e) { Cursor cursor = Cursors.Default; if (_isMouseDownInTabButton && e.Button == MouseButtons.Left) { cursor = Cursors.Hand; if (_isMovingTabButton) { UnitButton selected = _buttons[SelectedIndex]; if (selected.Contains(e.Location) == false) { if (_isDraggingTabButton) { ContinueButtonDrag(e.Location, ref cursor); } else { int index = -1; UnitButton underMouse = GetButtonFromPoint(e.Location, true, out index); if (underMouse != null) { bool displace = false; if (underMouse == _buttonDisplaced) { if (index < SelectedIndex) { displace = ButtonsRenderer.CanUndoDisplaceBack(underMouse, selected, e.Location); } else if (index > SelectedIndex) { displace = ButtonsRenderer.CanUndoDisplaceNext(underMouse, selected, e.Location); } } _buttonDisplaced = underMouse; if (displace) { _buttons[index] = selected; _buttons[SelectedIndex] = underMouse; _updatePositionsOnDraw = true; SelectedIndex = index; } } else { _isDraggingTabButton = BeginButtonDrag(selected, e.Location, ref cursor); } } } } else { _isMovingTabButton = _buttons[SelectedIndex].Contains(e.Location); _isDraggingTabButton = false; } } else if (GetButtonFromPoint(e.Location) != null) { cursor = Cursors.Hand; } CheckIfIsMouseOverScrollButtons(e.Location); if (IsMouseOverScrollBackButton && _firstShownButtonIndex > 0) { cursor = Cursors.Hand; } else if (IsMouseOverScrollNextButton && _canScrollNext) { cursor = Cursors.Hand; } int captionIndex = ButtonsRenderer.GetCaptionButtonIndex(_captionButtonsBounds, e.Location); if (captionIndex < 0 || captionIndex >= ButtonsCount) { captionIndex = -1; } else { cursor = Cursors.Hand; } if (_captionButtonIndexUnderMouse != captionIndex) { _captionButtonIndexUnderMouse = captionIndex; OnMouseMoveOverCaptionButton(captionIndex, e); Invalidate(); } int buttonIndex = -1; UnitButton buttonUnderMouse = GetButtonFromPoint(e.Location, false, out buttonIndex); if (buttonUnderMouse != null) { OnMouseMoveOverTabButton(buttonUnderMouse); } Cursor = cursor; base.OnMouseMove(e); }
/// <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> protected virtual void DrawButtonsLine(PaintEventArgs e) { ButtonsRenderer.DrawButtonsLine(e.Graphics, _clientBounds, _buttonsPanelBounds); }
/// <summary> /// 更新面板上的位置 /// </summary> private void UpdatePositions(Graphics graphics, bool forceChangeNotification) { Rectangle bounds = new Rectangle(); Rectangle pagesPanelBounds = _clientBounds; int buttonsCount = _buttons.Count; if (buttonsCount == 1 && ShowOneTabButton == false) { buttonsCount = 0; } if (buttonsCount != 0) { bounds = ButtonsRenderer.GetFirstButtonBounds(_clientBounds, false, 0, _buttons[0].Text, Font, _buttons[0].PageIcon, graphics); _buttons[0].SetBounds(bounds); for (int index = 1; index < _buttons.Count; index++) { bounds = ButtonsRenderer.GetNextButtonBounds(bounds, _buttons[index].Text, Font, _buttons[index].PageIcon, graphics); _buttons[index].SetBounds(bounds); } _buttonsPanelBounds = ButtonsRenderer.GetButtonsClipRectangle(_clientBounds, false, CaptionButtonsCount); _hasScrolls = ButtonsRenderer.HasScroll(_buttonsPanelBounds, bounds); if (_hasScrolls) { _buttonsPanelBounds = ButtonsRenderer.GetButtonsClipRectangle(_clientBounds, true, CaptionButtonsCount); } if (_hasScrolls) { int scrollPos = ButtonsRenderer.GetScrollPos(_buttons, _firstShownButtonIndex); bounds = ButtonsRenderer.GetFirstButtonBounds(_clientBounds, true, scrollPos, _buttons[0].Text, Font, _buttons[0].PageIcon, graphics); _buttons[0].SetBounds(bounds); for (int index = 1; index < _buttons.Count; index++) { bounds = ButtonsRenderer.GetNextButtonBounds(bounds, _buttons[index].Text, Font, _buttons[index].PageIcon, graphics); _buttons[index].SetBounds(bounds); } _scrollBackBounds = ButtonsRenderer.GetScrollBackButtonBounds(_buttonsPanelBounds); _scrollNextBounds = ButtonsRenderer.GetScrollNextButtonBounds(_buttonsPanelBounds); _canScrollNext = ButtonsRenderer.CanScrollNext(_buttons[ButtonsCount - 1], _scrollNextBounds) && _firstShownButtonIndex < ButtonsCount - 1; } pagesPanelBounds = ButtonsRenderer.GetClientRectangle(pagesPanelBounds); } _captionButtonsBounds = ButtonsRenderer.GetCaptionButtonsRectangle(_clientBounds, CaptionButtonsCount); if (_pagesPanelBounds != pagesPanelBounds || forceChangeNotification) { _pagesPanelBounds = pagesPanelBounds; pagesPanelBounds.Height++; //pagesPanelBounds.Inflate(-PagesPanelMargins, -PagesPanelMargins); OnPagesPanelBoundsChanged(pagesPanelBounds); } }