Massive bug in WinForms 2

S

schoenfeld1

Why does WinForms in .NET 2 paint container controls more times than
necessary?

Steps to reproduce:

1. Make a UserControl called 'Widget'. Put some buttons / labels / etc
inside this control.

2. Make a UserControl called 'Container'. Place a bunch of 'Widget'
controls inside here.

3. Override the Contaner.OnPaint method and put a breakpoint on
base.OnPaint(e);

4. Start your application but make sure that your app window and IDE
window do not overlap (make IDE window very small and thin for
example). This is to prevent paint calls triggered by overlapping
windows.

5. Observe on the Container.OnPaint method get called after every LEAF
NODE control gets rendered. That means, Container.OnPaint gets called
when the widget gets painted, when the widgets labels/buttons get
painted, etc..
 
F

Frans Bouma [C# MVP]

Why does WinForms in .NET 2 paint container controls more times than
necessary?

Steps to reproduce:

1. Make a UserControl called 'Widget'. Put some buttons / labels /
etc inside this control.

2. Make a UserControl called 'Container'. Place a bunch of 'Widget'
controls inside here.

3. Override the Contaner.OnPaint method and put a breakpoint on
base.OnPaint(e);

4. Start your application but make sure that your app window and IDE
window do not overlap (make IDE window very small and thin for
example). This is to prevent paint calls triggered by overlapping
windows.

5. Observe on the Container.OnPaint method get called after every
LEAF NODE control gets rendered. That means, Container.OnPaint gets
called when the widget gets painted, when the widgets labels/buttons
get painted, etc..

In a way, it's understandable: the widget control does an
InvalidateRect and by that gets a repaint, though that repaint causes
an invalidaterect of the container and thus that one gets a repaint as
well.

I do understand that they should have added some 2D clipping logic in
it so that if a topmost control performs an invalidate rect, the
container doesn't have to be repainted.

(though I now think that will go wrong if the topmost control is
transparent)

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 

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