/// <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); }