System.Windows.Forms.PictureBox.Dispose C# (CSharp) Method

Dispose() protected method

protected Dispose ( bool disposing ) : void
disposing bool
return void
		protected override void Dispose (bool disposing)
		{
			if (image != null) {
				StopAnimation ();
				image = null;
			}
			initial_image = null;

			base.Dispose (disposing);
		}

Usage Example

 public static void Set(string fpath)
 {
     string sfiletype = fpath.Substring(fpath.LastIndexOf(".")+1,(fpath.Length-fpath.LastIndexOf(".")-1)).ToLower();
     if (sfiletype == "bmp")
     {
          SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, fpath, 1); //调用,filename为图片地址,最后一个参数需要为1,0的话在重启后就变回原来的了
     }
     else
     {
         string bmp_path = Application.StartupPath + @"\wallpaper.bmp";
         FileInfo file_info = new FileInfo(bmp_path);
         if (file_info.Exists)
         {
             file_info.Delete();
             PictureBox picutrebox = new PictureBox();
             picutrebox.Image = Image.FromFile(fpath);
             picutrebox.Image.Save(bmp_path, ImageFormat.Bmp);
             picutrebox.Image.Dispose();
             picutrebox.Dispose();
         }
         else
         {
             PictureBox picutrebox = new PictureBox();
             picutrebox.Image = Image.FromFile(fpath);
             picutrebox.Image.Save(bmp_path, ImageFormat.Bmp);
             picutrebox.Image.Dispose();
             picutrebox.Dispose();
         }
         SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, bmp_path, 1);
     }
 }
All Usage Examples Of System.Windows.Forms.PictureBox::Dispose