How to detect changes in any form control in C #?

Can someone help me in detecting changes in any form control in C #? I have many controls in one form, and I need to disable the button if any of the control values ​​in the form change. I am looking for some inline functions / handler events / property and don't want to make a custom function for this.

I beg you, please.

+5
source share
2 answers

No, I don’t know about any event that fires whenever a control in a form changes.

( , , ).

, - :

foreach (Control c in this.Controls)
{
    c.TextChanged += new EventHandler(c_ControlChanged);
}

void c_ControlChanged(object sender, EventArgs e)
{

}

, , .

, TextChanged (, TextBoxes) - , , :

foreach (Control c in this.Controls)
{
    if (c is CheckBox)
    {
        ((CheckBox)c).CheckedChanged += c_ControlChanged;
    }
    else
    {
        c.TextChanged += new EventHandler(c_ControlChanged);
    }
}
+12

, INotifyPropertyChanged.

, -, , .

, , .

+4

All Articles