110,534
社区成员
发帖
与我相关
我的任务
分享
private bool zg1_MouseDownEvent(ZedGraphControl control, MouseEventArgs e)
{
// point-dragging is activated by an 'Alt' key and mousedown combination
if (Control.ModifierKeys == Keys.Alt)
{
GraphPane myPane = control.GraphPane;
PointF mousePt = new PointF(e.X, e.Y);
// find the point that was clicked, and make sure the point list is editable
// and that it's a primary Y axis (the first Y or Y2 axis)
if (myPane.FindNearestPoint(mousePt, out dragCurve, out dragIndex) &&
dragCurve.Points is PointPairList &&
dragCurve.YAxisIndex == 0)
{
// save the starting point information
startPt = mousePt;
startPair = dragCurve.Points[dragIndex];
// indicate a drag operation is in progress
isDragPoint = true;
// get the scale values for the start of the drag
//double startY2;
myPane.ReverseTransform(mousePt, out startX, out startY);
// if it's a Y2 axis, use that value instead of Y
//if (dragCurve.IsY2Axis)
// startY = startY2;
return true;
}
}
return false;
}
private bool zg1_MouseMoveEvent(ZedGraphControl control, MouseEventArgs e)
{
GraphPane myPane = control.GraphPane;
PointF mousePt = new PointF(e.X, e.Y);
// see if a dragging operation is underway
if (isDragPoint)
{
// get the scale values that correspond to the current point
double curX, curY; //, curY2;
myPane.ReverseTransform(mousePt, out curX, out curY);
// if it's a Y2 axis, use that value instead of Y
//if (dragCurve.IsY2Axis)
// curY = curY2;
// calculate the new scale values for the point
PointPair newPt = new PointPair(startPair.X + curX - startX, startPair.Y + curY - startY);
// save the data back to the point list
(dragCurve.Points as PointPairList)[dragIndex] = newPt;
// force a redraw
control.Refresh();
// tell the ZedGraphControl not to do anything else with this event
return true;
}
else
{
//change the cursor if the mouse is sufficiently close to a point
if (myPane.FindNearestPoint(mousePt, out dragCurve, out dragIndex) &&
dragCurve.Points is PointPairList &&
dragCurve.YAxisIndex == 0)
{
zg1.Cursor = Cursors.SizeAll;
}
else
{
zg1.Cursor = Cursors.Default;
}
}
// since we didn't handle the event, tell the ZedGraphControl to handle it
return false;
}
private bool zg1_MouseUpEvent(ZedGraphControl control, MouseEventArgs e)
{
if (isDragPoint)
{
// dragging operation is no longer active
isDragPoint = false;
}
return false;
}