Invalidate .vs. Refresh

  • Thread starter Thread starter ozbear
  • Start date Start date
O

ozbear

When creating my own classes derived from Control, when you
change some aspects of the object at design time, you need to
get the overridden OnPaint method called to reflect the visual
changes in the designer.

For example, changing a property, in the designer, that alters
a color.

I have been using the Invalidate method to cause a repaint in
design mode but Refresh works as well. Is there any practical
advantage of using one over the other?

Oz
 
ozbear said:
For example, changing a property, in the designer, that alters
a color.

I have been using the Invalidate method to cause a repaint in
design mode but Refresh works as well. Is there any practical
advantage of using one over the other?

Oz

Refresh invalidates the entire client area and child controls of the
control, whereas Invalidate gives you control over exactly *what* should
be invalidated.

This makes Invalidate more lightweight. If you have knowledge about what
changes affect a specific area of the control, then better use
Invalidate, as it will only update that specific area. Refresh is the
fire-and-forget method that will always update everything, and is thus
more costly (and often not necessary).
 
Back
Top