Hi Leandro, below you find what I wrote in the comment as code, it works for one form.
The MyApplicationSettings class is at the bottom, otherwise the forms designer will complain. If you want the multi-form solution, you have to give the MyApplicationSettings instance some global place to live. Form2 to Formn will then subscribe to the BackColorChanged event and provide their OnBackColorChanged event handler.
public partial class Form1 : Form
{
public MyApplicationSettings ApplicationSettings = new MyApplicationSettings();
public Form1()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
ApplicationSettings.BackColorChanged += OnBackColorChanged;
comboBoxFormBackColor.SelectedIndexChanged += OnComboBoxFormBackColorChanged;
comboBoxFormBackColor.Items.Add(System.Drawing.Color.Red);
comboBoxFormBackColor.Items.Add(System.Drawing.Color.Blue);
comboBoxFormBackColor.Items.Add(System.Drawing.Color.Green);
comboBoxFormBackColor.Items.Add(System.Drawing.Color.Magenta);
comboBoxFormBackColor.SelectedIndex = 0;
ApplicationSettings.FormBackColor = (System.Drawing.Color)comboBoxFormBackColor.SelectedItem;
}
private void OnComboBoxFormBackColorChanged(object sender, EventArgs e)
{
ApplicationSettings.FormBackColor = (System.Drawing.Color)comboBoxFormBackColor.SelectedItem;
}
private void OnBackColorChanged(object sender, EventArgs e)
{
this.BackColor = ApplicationSettings.FormBackColor;
}
}
public class MyApplicationSettings
{
private Color _formBackColor;
public System.Drawing.Color FormBackColor
{
get
{
return _formBackColor;
}
set
{
_formBackColor = value;
OnBackColorChanged();
}
}
public event EventHandler BackColorChanged;
protected void OnBackColorChanged()
{
EventHandler handler = BackColorChanged;
if (handler != null) handler(this, EventArgs.Empty);
}
}