在ZedGraph画完曲线之后,还想画几条参考线(方便对比多条曲线在某个感兴趣的时间点的值...)可是,画好之后,感觉拖拽过程反应迟钝。不知如何才能改进?
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;
}主要代码在其中了...
加这个贴:http://http://topic.csdn.net/u/20080528/15/6d98f4f7-ad19-434e-8e30-3ddd1c04e099.html
的分一并献上(哎,上贴又流标了)
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;
}主要代码在其中了...
加这个贴:http://http://topic.csdn.net/u/20080528/15/6d98f4f7-ad19-434e-8e30-3ddd1c04e099.html
的分一并献上(哎,上贴又流标了)
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货