protected override void OnMouseMove(MouseEventArgs e) { // Create a point representing current mouse position Point mousePos = new Point(e.X, e.Y); int index = 0; int count = _drawTabs.Count; // Search each draw cell for (; index < count; index++) { DrawTab dt = _drawTabs[index] as DrawTab; // Is mouse over this cell? if (dt.DrawRect.Contains(mousePos)) { // If the mouse is not over the hover item if (_hoverItem != dt.Index) { // And we are not already timing this change in hover if (_hoverOver != dt.Index) { // Start timing the hover change _hoverTimer.Start(); // Remember which item we are timing _hoverOver = dt.Index; } } break; } } // Failed to find an item? if (index == count) { // If we have a hover item or timing a hover change if ((_hoverOver != -1) || (_hoverItem != -1)) { // Stop any timing CancelHoverItem(); } } base.OnMouseMove(e); }
protected override void OnMouseDown(MouseEventArgs e) { // Only select a button or page when using left mouse button if (e.Button == MouseButtons.Left) { // Create a point representing current mouse position Point mousePos = new Point(e.X, e.Y); int count = _drawTabs.Count; // Search each draw cell for (int index = 0; index < count; index++) { DrawTab dt = _drawTabs[index] as DrawTab; // Is mouse pressed in this draw cell? if (dt.DrawRect.Contains(mousePos)) { // Prevent any hover timer expiring _hoverTimer.Stop(); // This becomes the current hover item _hoverItem = _selectedIndex; // Not timing a hover change _hoverOver = _hoverItem; // Will this cause a change in selection? if (_selectedIndex != dt.Index) { // Change selection and redraw _selectedIndex = dt.Index; Recalculate(); Invalidate(); } // Generate event to notify a click occured on the selection OnPageClicked(_selectedIndex); break; } } } }