Title: [C#] Background changer main window Author: Erb1tux Pastebin link: http://pastebin.com/QdEvkcKj First Edit: Saturday 13th of September 2014 05:22:48 PM CDT Last Edit: Saturday 13th of September 2014 05:22:48 PM CDT using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Microsoft.Win32; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks;     namespace Background_Changer {     public partial class BGChangerWindowMain : Form     {         public BGChangerWindowMain()         {             InitializeComponent();         }           #region Hotkey DLL         [DllImport("user32.dll")]         private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);           [DllImport("user32.dll")]         private static extern bool UnregisterHotKey(IntPtr hWnd, int id);           const int MOD_CONTROL = 0x0002;         const int MOD_SHIFT = 0x0004;         const int WM_HOTKEY = 0x0312;         #endregion               bool safeBg = false;         bool closepls = false;             private void Form1_Load(object sender, EventArgs e)         {             if (!Directory.Exists(@"bg\")) Directory.CreateDirectory(@"bg\");                 if (!Existant())                 MessageBox.Show("At least one Image is missing!\nPlease add each Image before continuing.", "Fatalaty", MessageBoxButtons.OK, MessageBoxIcon.Stop);             else if (Existant() && Properties.Settings.Default.setSafe)                 changeBg(false);               checkBoxSetSafe.Checked = Properties.Settings.Default.setSafe;             //             //Registering Hotkey             //                         RegisterHotKey(this.Handle, 1, MOD_CONTROL + MOD_SHIFT, (int)Keys.D);                         //             //Hide yo kids, hide yo wife, hide yo program             //             this.Hide();         }           private bool Existant()         {             if (File.Exists(@"bg\safe.png"))                 using (System.IO.Stream s = new System.Net.WebClient().OpenRead(@"bg\safe.png"))                 {                     System.Drawing.Image img = System.Drawing.Image.FromStream(s);                     pictureBoxSafe.BackgroundImage = img;                 }             else                 return false;             if (File.Exists(@"bg\lewd.png"))                 using (System.IO.Stream s = new System.Net.WebClient().OpenRead(@"bg\lewd.png"))                 {                     System.Drawing.Image img = System.Drawing.Image.FromStream(s);                     pictureBoxLewd.BackgroundImage = img;                 }             else                 return false;               return true;         }            protected override void WndProc(ref Message m)         {             if (m.Msg == WM_HOTKEY)                 changeBg(false);             base.WndProc(ref m);         }          private void changeBg(bool changeAlways)        {            if (!Existant())                return;                        Uri safe = new System.Uri(Application.StartupPath + @"\bg\safe.png");            Uri lewd = new System.Uri(Application.StartupPath +@"\bg\lewd.png");              if (safeBg && (!checkBoxSafeChange.Checked || changeAlways))            {                Wallpaper.Set(lewd, Wallpaper.Style.Tiled);                safeBg = false;                labelLewdActive.Visible = true;                labelSafeActive.Visible = false;            }            else            {                Wallpaper.Set(safe, Wallpaper.Style.Tiled);                safeBg = true;                labelLewdActive.Visible = false;                labelSafeActive.Visible = true;            }                        }             private void closeToolStripMenuItem_Click(object sender, EventArgs e)         {             closepls = true;             this.Close();         }           private void changeBackgroundToolStripMenuItem_Click(object sender, EventArgs e)         {             changeBg(true);           }           private void settingsToolStripMenuItem_Click(object sender, EventArgs e)         {             this.Show();         }           private void Form1_FormClosing_1(object sender, FormClosingEventArgs e)         {             if (!closepls)                 e.Cancel = true;             else                 UnregisterHotKey(this.Handle, 1);             this.Hide();                     }           private void button1_Click(object sender, EventArgs e)         {             this.Hide();         }           private void buttonCloseProgram_Click(object sender, System.EventArgs e)         {             closepls = true;             this.Close();         }           private void buttonChangeSafe_Click(object sender, System.EventArgs e)         {             if (openFileDialog1.ShowDialog() == DialogResult.OK)                 using (System.IO.Stream s = new System.Net.WebClient().OpenRead(openFileDialog1.FileName))                 {                     System.Drawing.Image img = System.Drawing.Image.FromStream(s);                     pictureBoxSafe.BackgroundImage = img;                     if (File.Exists(@"bg\safe.png")) File.Delete(@"bg\safe.png");                     File.Copy(openFileDialog1.FileName, @"bg\safe.png");                 }             else                 return;         }           private void buttonChangeLewd_Click(object sender, System.EventArgs e)         {             if (openFileDialog1.ShowDialog() == DialogResult.OK)                 using (System.IO.Stream s = new System.Net.WebClient().OpenRead(openFileDialog1.FileName))                 {                     System.Drawing.Image img = System.Drawing.Image.FromStream(s);                     pictureBoxLewd.BackgroundImage = img;                     if (File.Exists(@"bg\lewd.png")) File.Delete(@"bg\lewd.png");                     File.Copy(openFileDialog1.FileName, @"bg\lewd.png");                 }             else                 return;         }           private void buttonChangeBG_Click(object sender, System.EventArgs e)         {             changeBg(true);         }           private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)         {             this.Show();         }             private void checkBox1_CheckedChanged(object sender, System.EventArgs e)         {             Properties.Settings.Default.setSafe = checkBoxSetSafe.Checked;             Properties.Settings.Default.Save();         }       } }