I have a Winform application which uses colour to highlight certain things. I would like to allow the users to change \'their\' colours. As an exercise, I thought I would cr
Just try refreshing it:
private void button1_Click(object sender, EventArgs e)
{
Colours colours = this.propertyGrid1.SelectedObject as Colours;
colours.Reset();
this.propertyGrid1.Refresh();
}
Assuming you will have more properties, you can use your PropertyChanged
event. I would modify your Colour class like this:
public class Colours : INotifyPropertyChanged {
public event PropertyChangedEventHandler PropertyChanged;
private Color _ColourP1;
public void Reset() {
this.ColourP1 = Color.Red;
}
private void OnChanged(string propName) {
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
public Color ColourP1 {
get { return _ColourP1; }
set {
_ColourP1 = value;
OnChanged("ColourP1");
}
}
}
Then your form would look like this:
public Form1() {
InitializeComponent();
Colours colours = new Colours();
colours.PropertyChanged += colours_PropertyChanged;
this.propertyGrid1.SelectedObject = colours;
}
private void colours_PropertyChanged(object sender, PropertyChangedEventArgs e) {
this.propertyGrid1.Refresh();
}
private void button1_Click(object sender, EventArgs e) {
((Colours)this.propertyGrid1.SelectedObject).Reset();
}