日期:2014-05-18  浏览次数:21001 次

C# 怎样清除上一次绘制的曲线
在画布上画好了格网,要在格网上画出闭合的几何图形,当画第二个几何图时要清除第一个图,但不能清底图的格网,如何实现请大侠们指点

------解决方案--------------------
建议绘制的时候把需要绘制的内容都通过数据的方式保存在内存里,然后窗口绘制的时候根据这些数据来绘制,这样可以避免意料之外引发的窗口的窗口重绘导致内容丢失

至于你要画第几何图的时候就把第一个几何图的数据删除,然后调用Invalidate()让窗口重绘就行了
------解决方案--------------------
在pictureBox1_Paint里面画网格,然后在定义函数画图
 private void button1_Click(object sender, EventArgs e)//画你第一次的图
{
Graphics s = pictureBox1.CreateGraphics();
SolidBrush bru = new SolidBrush(Color.Red);
Pen pen = new Pen(Color.Black,2);
s.DrawEllipse(pen, 20, 20, 20, 20);

}

private void pictureBox1_Paint(object sender, PaintEventArgs e)//画的网格,这是我做得象棋游戏里的如你想要可以看下,接着给你把资源地址发给你
{
Graphics ma = e.Graphics;
////绘图模式默认为粗糙模式,将会出现锯齿!
//ma.SmoothingMode = SmoothingMode.AntiAlias;
//ma.SmoothingMode = SmoothingMode.HighQuality;
SolidBrush brush = new SolidBrush(Color.Black);
Pen Linecolor = new Pen(Color.Black, 2);
for (int i = 0; i < 9; i++)//上边一块
ma.DrawLine(Linecolor, 50 + i * 55, 50, 50 + i * 55, 270);
for (int i = 0; i < 9; i++)//下边一块
ma.DrawLine(Linecolor, 50 + i * 55, 325, 50 + i * 55, 545);
for (int j = 0; j < 10; j++)//横线
ma.DrawLine(Linecolor, 50, 50 + j * 55, 490, 50 + j * 55);
ma.DrawLine(Linecolor, 50, 50, 50, 525);//画边上的两条竖线
ma.DrawLine(Linecolor, 490, 50, 490, 525);
ma.DrawLine(Linecolor, 215, 50, 325, 160);//画士走的斜线
ma.DrawLine(Linecolor, 215, 160, 325, 50);
ma.DrawLine(Linecolor, 215, 545, 325, 435);
ma.DrawLine(Linecolor, 215, 435, 325, 545);
ma.DrawString("楚河", new Font("隶书", 30), brush, 100, 275);
ma.DrawString("汉界", new Font("隶书", 30), brush, 345, 275);
}

private void button2_Click(object sender, EventArgs e)//清除第一次画得图
{
pictureBox1.Refresh();
}
------解决方案--------------------
http://download.csdn.net/source/604790
象棋游戏的地址,有兴趣可以看下