mardi 31 mars 2015

Invalidate() custom control on every property change?

I am working on a custom winforms control that exposes a lot of properties that affect how the control looks (different colors for background, text and for different states like hover, click as well as icons etc). A change to one of these properties makes a repaint necessary so at the moment every property has a getter and setter with the setter calling Invalidate(). This is extremely annoying to code and if multiple properties are changed at once, every single one of them causes a repaint even though one repaint at the end would be enough.


I had the following ideas but I don't know if they are possible or how to implement them:



  1. cache property changes for a few milliseconds and then Invalidate()

  2. use some kind of reflection to detect whether the caller is going to change another property in the next line and if so delay the call to Invalidate()

  3. maybe some Attributes before the properties that make a repaint necessary or a List of all such Properties that is expanded to the getters/setters at compile time


Can you give me some advice if these ideas make sense/are possible and point me to how to implement them?


Aucun commentaire:

Enregistrer un commentaire