private bool zedGraphControl_MouseDownEvent(ZedGraphControl sender, MouseEventArgs e)
{
if (ReadonlyCurve)
return false;
CurveItem curve;
int dragPointIndex;
// if CTRL is pressed, and we're not near a specific point, add a new point
if (Control.ModifierKeys.HasFlag(Keys.Control) &&
!zedGraphControl.GraphPane.FindNearestPoint(e.Location, out curve, out dragPointIndex)) {
// only add if we've actually clicked on the pane, so make sure the mouse is over it first
if (zedGraphControl.MasterPane.FindPane(e.Location) != null) {
PointPairList pointList = zedGraphControl.GraphPane.CurveList[0].Points as PointPairList;
double newX, newY;
zedGraphControl.GraphPane.ReverseTransform(e.Location, out newX, out newY);
//Verify the point is in the usable bounds.
if (newX > 100)
{
newX = 100;
}
else if(newX < 0)
{
newX = 0;
}
if (newY > 100)
{
newY = 100;
}
else if (newY < 0)
{
newY = 0;
}
pointList.Insert(0, newX, newY);
pointList.Sort();
zedGraphControl.Invalidate();
}
}
// if the ALT key was pressed, and we're near a point, delete it -- but only if there would be at least two points left
if (Control.ModifierKeys.HasFlag(Keys.Alt) &&
zedGraphControl.GraphPane.FindNearestPoint(e.Location, out curve, out dragPointIndex)) {
PointPairList pointList = zedGraphControl.GraphPane.CurveList[0].Points as PointPairList;
if (pointList.Count > 2) {
pointList.RemoveAt(dragPointIndex);
pointList.Sort();
zedGraphControl.Invalidate();
}
}
if (!Curve.IsLibraryReference && e.Button == MouseButtons.Left && sender.DragEditingPair != null)
{
txtXValue.Text = sender.DragEditingPair.X.ToString();
txtYValue.Text = sender.DragEditingPair.Y.ToString();
txtXValue.Enabled = txtYValue.Enabled = btnUpdateCoordinates.Enabled = true;
}
return false;
}