public void saveAndSet(Image img) { try { if (File.Exists(backgroundPath)) { try { File.Delete(backgroundPath); img.Save(backgroundPath); Wallpaper.Set(new Uri(backgroundPath), Wallpaper.Style.Centered); img.Dispose(); File.Delete(defPath); } catch { img.Save(defPath); Wallpaper.Set(new Uri(defPath), Wallpaper.Style.Centered); img.Dispose(); //File.Delete(backgroundPath); } } else { img.Save(backgroundPath); Wallpaper.Set(new Uri(defPath), Wallpaper.Style.Centered); File.Delete(defPath); } } catch { MessageBox.Show("Unstability error.", "Err"); } }
private void button2_Click(object sender, EventArgs e) { Wallpaper.Set(new Uri(Application.StartupPath + "\\layout.bmp"), Wallpaper.Style.Centered); }