i have made a windows form.In that form i have three button RED, GREEN, PINK
when i click RED the form color goes PINK
when i click GREEN the form color goes GREEN
when i click PINK the form color goes PINK.
the problem is suppose user click PINK then form color goes pink but when the user open the same form again its comes to it default color.I want code to save the user setting.
plz help me [email protected]
Loading
AlanPosted Aug 2, 2008, 2:06 PM
An easy way to do this is to handle the FormClosing event and save the form's current background color to a text file. Then, when the form loads, the text file can be read and the background color set to the appropriate color.
Here's some code:
private
void Form1_Load(object sender, EventArgs e){
if (System.IO.File.Exists("formcolor.txt")){
string formColor = System.IO.File.ReadAllText("formcolor.txt"); switch(formColor){
case "Red" : this.BackColor = Color.Red; break; case "Green" : this.BackColor = Color.Green; break; case "Pink" : this.BackColor = Color.Pink; break; default: this.BackColor = SystemColors.Control; //say break;}
}
}
private
void Form1_FormClosing(object sender, FormClosingEventArgs e){
System.IO.
File.WriteAllText("formcolor.txt", this.BackColor.Name);}
Don't forget to add the eventhandler skeletons from the VS designer so that they are wired up correctly.