我正在尝试创建一个.NET应用程序,用于可视化表示节点网络。节点是可以用鼠标拖动并使用Graphics.DrawLine进行连接的Drawing.Rectangle实例。如下所示。

为了避免矩形在拖动时被重新绘制而留下难看的序列,我在组件上调用Graphics.Clear,并在每次调用Mouse_Move时重新绘制每个矩形和线条。但这导致了一个非常丑陋的闪光效果,因为我认为它被调用得不够快……
是否有一些.NET函数或更好的方法来重新绘制此场景,以便刷新看起来更平滑?
我的代码:
private void NodesPanel_MouseMove(object sender, MouseEventArgs e)
{
if (MouseButtons.Left == e.Button)
{
if (currentlyClickedNode != null)
{
surface.Clear(Color.White);
drawUnselectedNodes();
drawConnections();
if (!ClickedNodeGate) // Clicked on the node
{
currentlyClickedNode.setPosition(e.X - QuestNode.NODE_WIDTH / 2, e.Y - QuestNode.NODE_HEIGHT / 2);
currentlyClickedNode.drawMe(surface, penl);
}
else // clicked on the gate
{
drawingLine = true;
currentlyClickedNode.drawMe(surface, penl);
DrawingHelper.DrawLine(surface, penl, currentlyClickedNode.getGatePosition(), new Vector2D(e.X, e.Y));
}
}
}
}感谢您所能给予的任何帮助。
发布于 2012-11-06 02:06:51
这是一个非常复杂的主题,有成千上万种不同的方法可以做到这一点。您将不得不学习更多关于Windows图形和窗口子系统的知识。您可能希望从http://shop.oreilly.com/product/0790145369079.do开始
https://stackoverflow.com/questions/13237752
复制相似问题