日期:2014-05-17  浏览次数:20746 次

c# 如何让刚才画的线消失?
小弟C# 新手,用C# 划线时画出来了,那我如何才能让刚才画的线消失呢?代码如下
  private void Form1_Paint(object sender, PaintEventArgs e)
  {
  Graphics g = this.CreateGraphics();
  Pen p = new Pen(Color.Green, 1);
  g.DrawLine(p,20, 650, 20, 50);
  g.DrawLine(p, 20, 50, 1020, 50);
  g.DrawLine(p, 1020, 50, 1020, 650);
  g.DrawLine(p, 20, 650, 1020, 650);
  g.Dispose();
  p.Dispose();
  }

------解决方案--------------------
C# code
Graphics g = this.CreateGraphics();
                Pen p = new Pen(Color.Green, 1);
                g.DrawLine(p, 20, 650, 20, 50);
                g.DrawLine(p, 20, 50, 1020, 50);
                g.DrawLine(p, 1020, 50, 1020, 650);
                g.DrawLine(p, 20, 650, 1020, 650);
                g.Clear(this.BackColor);//清除
                g.Dispose();
                p.Dispose();