我在本地硬盘有个图片!!!
  我在一个按扭事件中 实现读取该图片,然后显示在 pictureBox1 上
   
  在另一个按扭 马上执行删除这个图象文件  发生错误 说这个图象 正在被一个进程使用》  该怎么删除该图象啊?????????????  1读:
   System.Drawing.Image IG=System.Drawing.Image.FromFile(ImageFullName);
pictureBox1.Image=IG;   2删除:
   DirectoryInfo theFolder=new DirectoryInfo(ImagePaths);
if(theFolder.Exists)
{
theFolder.Delete(true);
//MessageBox.Show(ImagePaths+"删除成功!");
}
else
{
//MessageBox.Show(ImagePaths+"删除失败!"); }

解决方案 »

  1.   

    因为你的那个图片被button1调用后在picture中使用着,所以删除不了,你可以试试,先不用button1调用picture,而直接用button2删除,肯定是可以的
      

  2.   

    try
    delete before 
    pictureBox1.Image=null;
      

  3.   

    --这样试试:if (pictureBox1.Image == null)
    {
        if(theFolder.Exists)
            theFolder.Delete(true);
        else
            MessageBox.Show("没有图片可删除!");
    }
    else
    {
        pictureBox1.Image.Dispose ();
        if(theFolder.Exists)
            theFolder.Delete(true);
        else
            MessageBox.Show("没有图片可删除!");
    }
      

  4.   

    //稍微改一下:
    pictureBox1.Image.Dispose ();改成pictureBox1.Dispose ();if (pictureBox1.Image == null)
    {
        if(theFolder.Exists)
            theFolder.Delete(true);
        else
            MessageBox.Show("没有图片可删除!");
    }
    else
    {
        pictureBox1.Dispose ();
        if(theFolder.Exists)
            theFolder.Delete(true);
        else
            MessageBox.Show("没有图片可删除!");
    }
      

  5.   

    这样做
    private void button1_Click(object sender, System.EventArgs e)
    {
    System.IO.FileStream fs = new System.IO.FileStream("C:\\b.bmp",System.IO.FileMode.Open);
                this.pictureBox1.Image = System.Drawing.Image.FromStream(fs);
    fs.Close();
    } private void button2_Click(object sender, System.EventArgs e)
    {
    System.IO.File.Delete("C:\\b.bmp");
    }