I'm trying to set up my form to load its BackgroundImage
from a path listed in a .txt file.
The contents of the text file look like this:
System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Application Name", "Skins", "Background.png")
When the form loads, I run this code:
//LOAD FORM
string BackgroundSkinsPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Application Name", "Skins", "Skin.cfg");
this.BackgroundImage = Image.FromFile(System.IO.File.ReadAllText(BackgroundSkinsPath));
The contents of that text file can be changed by the user clicking on a button relating to a different background image:
//CHANGE BG IMAGE
private void ChangeBGButton_Click(object sender, EventArgs e)
{
string BackgroundSkinsPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Application Name", "Skins", "Skin.cfg");
System.IO.File.WriteAllText(BackgroundSkinsPath, "System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Application Name", "Skins", "Background2.png")");
this.BackgroundImage = Image.FromFile(System.IO.File.ReadAllText(BackgroundSkinsPath));
}
The reason I want to write the background image location to a file, is so that the next time the user loads the application, it will have the background image they've chosen, and this is the only way I can think of to do this.
The problem is, the code I've written doesn't work, and I'm not sure how to fix it.
I want the user to be able to choose a background image for the application from a folder in their "My Documents" folder (via a button or similar), and have the application remember which image they chose the next time they start the application.