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)…
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?).
I tried to do this (obviously, it didn’t work…):
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();
}
Replace this line
To this one