Reputation: 455
I have changed my app.config
file to allow the user to change the color scheme of the program. I can figure out how to change the background color of the form they are on where they change these settings:
Color colBackColor = Properties.Settings.Default.basicBackground;
this.BackColor = colBackColor;
But how can I change all of my forms background color? It's like I still want to pass all my forms to a function. I already asked that question and someone told me to use the app.config
file. Now that I have done that, am I using it wrong?
Upvotes: 3
Views: 2697
Reputation: 63317
It's simply that you need a base form from which all your forms in your project have to inherit:
public class FormBase : Form {
protected override void OnLoad(EventArgs e){
Color colBackColor = Properties.Settings.Default.basicBackground;
BackColor = colBackColor;
}
}
//Then all other forms have to inherit from that FormBase instead of the standard Form
public class Form1 : FormBase {
//...
}
public class Form2 : FormBase {
//...
}
public interface INotifyChangeStyle {
void ChangeStyle();
}
public class FormBase : Form, INotifyChangeStyle {
protected override void OnLoad(EventArgs e){
ChangeStyle();
}
public void ChangeStyle(){
//Perform style changing here
Color colBackColor = Properties.Settings.Default.basicBackground;
BackColor = colBackColor;
//--------
foreach(var c in Controls.OfType<INotifyChangeStyle>()){
c.ChangeStyle();
}
}
}
public class MyButton : Button, INotifyChangeStyle {
public void ChangeStyle(){
//Perform style changing here
//....
//--------
foreach(var c in Controls.OfType<INotifyChangeStyle>()){
c.ChangeStyle();
}
}
}
//... the same for other control classes
Upvotes: 5