Can't seem to change properties of objects in winforms C#

This is a bit of a confusing scenario. Basically, I'm trying to set a button's color when I use setter for a private variable that I store its color in.

First off, I have a seperate window for customizing stuff. When I change the button color, I want to change every button in this window as well. I have it stored in a static variable in my main form class.

public static frm_custom customizer;

This is the setter for the variable in question.

private Color _buttonColor;
public Color buttonColor
{
    get { return this._buttonColor; }
    set
    {
        this.btn_input.BackColor = buttonColor;
        this._buttonColor = buttonColor;
        if (Application.OpenForms.OfType<frm_custom>().Count() == 1)
        {
            customizer.setButtonColor(buttonColor);
        }
    }
}

Strangely, it doesn't effect the color at all. Did I do something wrong?

Jon Skeet
people
quotationmark

Did I do something wrong?

Yes. Your setter is just fetching the existing property value:

this.btn_input.BackColor = buttonColor;
this._buttonColor = buttonColor;

You meant to use value, which is the implicit parameter name for the setter:

this.btn_input.BackColor = value;
this._buttonColor = value;

(Ditto for your if block, but it's hard to tell how that's meant to work as it's not valid C# at the moment.)

As a side note, I'd strongly urge you to start following .NET naming conventions, which include capital letters for properties - so ButtonColor rather than buttonColor.

people

See more on this question at Stackoverflow