private void panelDraw_MouseDown(object sender, MouseEventArgs e) { _mouseIsDown = true; _lastMouseX = e.X; ODGraphLegendItem clicked = null; if (LegendDock == LegendDockType.Bottom) { clicked = _legendItems. FirstOrDefault(x => new Rectangle(x.LocationBox.X + _scrollOffsetX, x.LocationBox.Y, x.LocationBox.Width, x.LocationBox.Height) .Contains(e.X, e.Y)); } else { clicked = _legendItems. FirstOrDefault(x => new Rectangle(x.LocationBox.X, x.LocationBox.Y + panelDraw.AutoScrollPosition.Y, x.LocationBox.Width, x.LocationBox.Height) .Contains(e.X, e.Y)); } if (clicked == null) { return; } clicked.IsEnabled = !clicked.IsEnabled; clicked.Filter(); }
private void panelDraw_MouseMove(object sender, MouseEventArgs e) { foreach (ODGraphLegendItem legendItem in _legendItems) //reset hovered status. { legendItem.Hovered = false; } if (!_mouseIsDown) //hovering { ODGraphLegendItem hovered = null; if (LegendDock == LegendDockType.Bottom) { hovered = _legendItems //find the hovered item. .FirstOrDefault(x => new Rectangle(x.LocationBox.X + _scrollOffsetX, x.LocationBox.Y, x.LocationBox.Width, x.LocationBox.Height) .Contains(e.X, e.Y)); } else { hovered = _legendItems //find the hovered item. .FirstOrDefault(x => new Rectangle(x.LocationBox.X, x.LocationBox.Y + panelDraw.AutoScrollPosition.Y, x.LocationBox.Width, x.LocationBox.Height) .Contains(e.X, e.Y)); } if (hovered == null) //not hovering over a box, don't mark any hovered and redraw. { panelDraw.Invalidate(); return; } hovered.Hovered = true; //hovering over a box, mark that box as hovered and redraw. panelDraw.Invalidate(); } else //dragging { if (LegendDock != LegendDockType.Bottom) //no dragging for Left-Docked legends; they get a scrollbar. { return; } int move = e.X - _lastMouseX; _lastMouseX = e.X; _scrollOffsetX += move; int maxScroll = _contentWidth - panelDraw.Width; if (Math.Abs(_scrollOffsetX) > maxScroll) { _scrollOffsetX = -maxScroll; } if (_scrollOffsetX > 0) { _scrollOffsetX = 0; } panelDraw.Invalidate(); } }