拖拽一条参考线时,感觉反应迟钝,如何改进?

jacksu19 2008-06-03 03:18:32
在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
的分一并献上(哎,上贴又流标了)
...全文
341 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
kingkongzhang 2009-09-23
  • 打赏
  • 举报
回复
顶一下

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧