1

I have a C# Windows Form project. When i place a control, for example a label, it will have all the default properties. If I change one of these properties, for example, changing BorderStyle from "None" to "FixedSingle", the "FixedSingle" will be bold because it is changed from the default. Therefore, I know visual studio can recognize when a property is changed from the default. My question is, can I find all of these changed properties for all controls in a form, and output them?

Here is an example of pseudo code that it may look like:

foreach (Control ctrl in this.Controls)
{
    foreach (var property in ctrl)
    {
        if (property.Value != property.DefaultValue)
        {
            Console.WriteLine(property + ":" + property.Value)
        }
    }
}
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
Betwist
  • 19
  • 1
  • Does this answer your question? [Get the default value of a property given its name](https://stackoverflow.com/questions/6074055/get-the-default-value-of-a-property-given-its-name) and [How can I retrieve previous value of a variable?](https://stackoverflow.com/questions/34385679/how-can-i-retrieve-previous-value-of-a-variable) and [How to capture old value and new value in INotifyPropertyChanged implementation of PropertyChanged event in C#](https://stackoverflow.com/questions/47723876/how-to-capture-old-value-and-new-value-in-inotifypropertychanged-implementation) –  Jun 11 '21 at 12:04
  • 2
    You might want to scan the designer.cs file. Things that made it there are likely to be not default values. – Ralf Jun 11 '21 at 12:04
  • Other possiblity would be to create a instance of type you would to check (without touching properties of that instance). And compare properties of that instance with the instance you want to actually check. You might need to filter properties somehow then to exclude irrelevant properties. Like the handle or so. – Ralf Jun 11 '21 at 12:07
  • And be aware that a property might be a complex class by itself and you might need to recurse into the classes structures to find actual differences. – Ralf Jun 11 '21 at 12:09
  • [.NET DefaultValue attribute](https://stackoverflow.com/questions/2329868/net-defaultvalue-attribute) –  Jun 11 '21 at 12:10
  • why do you want to do this? what is the end goal? – JonasH Jun 11 '21 at 12:59

0 Answers0