private void button2_Click(object sender, System.EventArgs e)  //画线
{
Bitmap bmp = new Bitmap(300,400);
Graphics gp = Graphics.FromImage(bmp);
gp.DrawLine(new Pen(Color.Black), 0, 20, 100, 20);
pictureBox1.Image = bmp;
} private void button3_Click(object sender, System.EventArgs e)  //清除
{
pictureBox1.Image = null;
}

解决方案 »

  1.   

    pictureBox1.CreateGraphics().Dispose();
    if (MyControlArray.Count>2)
    {
    pictureBox1.CreateGraphics().CompositingQuality = CompositingQuality.GammaCorrected;
    pictureBox1.CreateGraphics().DrawLine(
    new Pen(System.Drawing.Color.Red),
    MyControlArray[0].Location.X-iwidth,MyControlArray[0].Location.Y-iheight,
    MyControlArray[1].Location.X-iwidth,MyControlArray[1].Location.Y-iheight);
    }pictureBox1.Image 是我加入的一张图片...
    我在图片上画的线.我想把线清了啊
      

  2.   

    可以清指定矩形块的图形:
    Invalidate ( System.Drawing.Rectangle rc )
    摘要:
     使控件的指定区域无效(将其添加到控件的更新区域,下次绘制操作时将重新绘制更新区域),并向控件发送绘制消息。  参数:
    rc: 一个 System.Drawing.Rectangle 对象,它表示要使之无效的区域。
      

  3.   

    Invalidate  
    Refresh
      

  4.   

    一楼的清除picturebox太不敬业了。
      

  5.   

    Invalidate  
    Refresh其实这个就可以了
    就是重新画一便背景,这样不就清除了么,后后所有的图像操作都用重绘来处理
      

  6.   

    pictureBox1.Image = null;
    Form1.Refresh();