Invalidate .vs. Refresh

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
 
W

Willem van Rumpt

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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top