/// <summary> /// Chart MouseClick event handler /// Function1:Expansion is returned before one /// Function2:1 point select / all delete /// Function3:1 point add select / 1 point delete /// </summary> /// <param name="sender">object</param> /// <param name="e">MouseEventArgs</param> private void Chart_MouseClick(object sender, MouseEventArgs e) { if (_radioButtonScaling.Checked) { if (e.Button == MouseButtons.Right) { // The right-click of a mouse // Expansion is returned before one(Function1) SimcaGraphZoomHistoryItem histItem = new SimcaGraphZoomHistoryItem(); if (_graphZoomHistory.PopItem(out histItem)) { // It succeeds in the position data acquisition in front of one. UpdateGraphGridInterval(histItem.MinX, histItem.MinY, histItem.MaxX, histItem.MaxY, false); //double center = (_chart.ChartAreas[0].AxisX.Maximum - _chart.ChartAreas[0].AxisX.Minimum) / 2.0; //center += _chart.ChartAreas[0].AxisX.Minimum; //double width = histItem.MaxX - histItem.MinX; //double newLeft = center - (width / 2.0); //center = (_chart.ChartAreas[0].AxisY.Maximum - _chart.ChartAreas[0].AxisY.Minimum) / 2.0; //center += _chart.ChartAreas[0].AxisY.Minimum; //double height = histItem.MaxY - histItem.MinY; //double newBottom = center - (height / 2.0); //UpdateGraphGridInterval(newLeft, newBottom, newLeft + width, newBottom + height, false); } } } else { Keys key = new Keys(); key = Control.ModifierKeys & (Keys.Control | Keys.Shift); if (e.Button == MouseButtons.Left) { // Select Points-1 1point select / all delete(Function2) if (key == Keys.None) { // 1 point select / all delete(Function2) // A selective state is initialized. foreach (Series item in _chart.Series) { foreach (DataPoint point in item.Points) { point.SetCustomProperty(PROPERTY_NAME_SELECTED, NOT_SELECTED); point.MarkerBorderColor = point.MarkerColor; } } // It set "Selected", if it is on a point. HitTestResult hitResult; hitResult = _chart.HitTest(((MouseEventArgs)e).X, ((MouseEventArgs)e).Y, ChartElementType.DataPoint); if (hitResult.ChartElementType == ChartElementType.DataPoint) { int index = hitResult.PointIndex; DataPoint data = hitResult.Series.Points[index]; hitResult.Series.Points[index].SetCustomProperty(PROPERTY_NAME_SELECTED, SELECTED); hitResult.Series.Points[index].MarkerBorderColor = SELECTED_MARKER_BORDER_COLOR; } ChangeSelect(false); } if (key == Keys.Control) { // 1 point add select / 1 point delete(Function3) HitTestResult hitResult; hitResult = _chart.HitTest(((MouseEventArgs)e).X, ((MouseEventArgs)e).Y, ChartElementType.DataPoint); if (hitResult.ChartElementType == ChartElementType.DataPoint) { int index = hitResult.PointIndex; if (hitResult.Series.Points[index].GetCustomProperty(PROPERTY_NAME_SELECTED) == SELECTED) { hitResult.Series.Points[index].SetCustomProperty(PROPERTY_NAME_SELECTED, NOT_SELECTED); hitResult.Series.Points[index].MarkerBorderColor = hitResult.Series.Points[index].MarkerColor; } else { hitResult.Series.Points[index].SetCustomProperty(PROPERTY_NAME_SELECTED, SELECTED); hitResult.Series.Points[index].MarkerBorderColor = SELECTED_MARKER_BORDER_COLOR; } ChangeSelect(false); } } } } }
/// <summary> /// Chart MouseUp event handler /// Function1:The end of range selection(Expansion) /// Function2:The end of range selection(Point selection) /// </summary> /// <param name="sender">object</param> /// <param name="e">MouseEventArgs</param> private void Chart_MouseUp(object sender, MouseEventArgs e) { // Get mouse position(Graph coordinates) double x; double y; try { x = _chart.ChartAreas[0].AxisX.PixelPositionToValue(e.X); y = _chart.ChartAreas[0].AxisY.PixelPositionToValue(e.Y); } catch (ArgumentException) { InitMouseFunction(); return; } catch (InvalidOperationException) { InitMouseFunction(); return; } double minX = Math.Min(_moveStartX, x); double maxX = Math.Max(_moveStartX, x); double minY = Math.Min(_moveStartY, y); double maxY = Math.Max(_moveStartY, y); if (_radioButtonScaling.Checked) { if (_zoomAreaSelect) { // Expansion(Function1) if (((maxX - minX) <= 0.001) || ((maxY - minY) <= 0.001)) { InitMouseFunction(); return; } SimcaGraphZoomHistoryItem histItem = new SimcaGraphZoomHistoryItem(); histItem.MinX = _chart.ChartAreas[0].AxisX.Minimum; histItem.MaxX = _chart.ChartAreas[0].AxisX.Maximum; histItem.MinY = _chart.ChartAreas[0].AxisY.Minimum; histItem.MaxY = _chart.ChartAreas[0].AxisY.Maximum; _graphZoomHistory.PushItem(histItem); UpdateGraphGridInterval(minX, minY, maxX, maxY, false); } } else { if (_pointAreaSelect) { // Point selection(Function2) foreach (Series item in _chart.Series) { foreach (DataPoint point in item.Points) { // Range outside is processing exclusion. if ((minX > point.XValue) || (maxX < point.XValue) || (minY > point.YValues[0]) || (maxY < point.YValues[0])) { continue; } // Set "Selected" point.SetCustomProperty(PROPERTY_NAME_SELECTED, SELECTED); point.MarkerBorderColor = SELECTED_MARKER_BORDER_COLOR; } } // Change of a selective points is notified. ChangeSelect(false); } } InitMouseFunction(); }