title: Setting the background image of a form using an external file - Windows Forms
body: <p>I'm trying to add an option for my Windows Froms application which will allow the user to change the background of a certain form to a picture from his computer (let's say a .png type of file)...</p>
  
  <p>How do I get the file from the computer and "convert" it to an Image type? Do I need to add it somehow to properties.resources lib? (and if so, how?).</p>
  
  <p>I tried to do this (obviously, it didn't work...):</p>
  
  <pre><code>var FD = new System.Windows.Forms.OpenFileDialog();
  FD.Filter = "png files|*.png";
  if (FD.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  {
      string fileToOpen = FD.FileName;
  
      System.IO.FileInfo File = new System.IO.FileInfo(FD.FileName);
      BackgroundImage = FD.OpenFile();
  }
  </code></pre>