Alex Clark
8/19/2008 8:15:00 PM
Hi Peter,
> All due respect, that's not a very useful description of the problem. :)
lol, I know, sorry, I'll try to clear that up a bit below.
> It sounds to me as though the controls aren't getting painted at all. So
> I'm not sure what it means for it to be "incredibly slow".
The control *does* get repainted, but it's laggy. If I drag calculator over
my form, the calculator window sort of "streaks" across it, leaving ghostly
images behind on the controls. Eventually they repaint themselves but it
can take a few seconds. It's as though there's a long delay between the
Invalidate and Paint calls, but I don't have any specific code in there that
would cause that. It's just taking a long time to refresh itself, it seems.
> That said, you mention that your application is "covered with these custom
> controls". How many? The fact is, there are practical limits to just how
> many controls you can put in a window and still expect reasonable drawing
> performance. If you have a large number, performance will suffer.
In all honesty it doesn't matter if it's covered in them or if it's just
one, the problem happens regardless. The most I'd fit on screen would be
roughly 10 - we're talking full width, and about 64px height (sort of like
list view items stacked one atop the other).
> It's also impossible to evaluate any sort of performance issue with just a
> code snippet. You should post a concise-but-complete code sample that
> reliably demonstrates the problem.
I know, sorry, should've posted a snippet but the project is complex. I'll
try to extract the relevant stuff into a sample repro project.
> Also, because this is a performance issue, you should be as specific about
> the details as you can. What methods are being called? How long do they
> take to execute? How often are they called? How sensitive to the number
> of controls being used is the issue? That sort of thing. Finally, it's
> important to be clear about what the system configuration is, especially
> the video card and CPU.
Methods: barely any. Once I've created an appropriate bitmap (that's done
early on) it's pretty much as simple as what I posted in the OP. I override
OnPaint, and call e.Graphics.DrawImage with my "here's one I made earlier"
bitmap. I clip it so that it should only repaint the invalidated area as
well. That is literally all it's doing, but between it getting invalidated
(me dragging an app over the top of it) and it actually refreshing, there
can be as much as a 3s delay (if I'm still rapidly dragging the other app
around the screen). CPU usage is high at the time as well.
Not really sensitive to the number of controls, it's slow with one, it's
slow with 12.
System is moderate spec, XP Pro x64, 2GB DDR800, Pentium D 3.4, PCI Express
128mb Radeon card.
> As a test, you could try using some built-in .NET control instead of your
> own in an otherwise-identical program and see how performance compares.
> That would at least give some information as to whether the performance
> issue is typical, or specific only to your custom control.
No contest, if I use a dozen large Buttons, ComboBoxen, or even ListViews
the repainting is snappy. Ironically I did a test a while back with a .NET
Panel control where I was painting a complex gradient bitmap with bubbles on
the background (just handling the PaintBackground event). With clipping and
some smart caching of the bitmap, performance was beautiful and snappy, even
in Debug mode.
Maybe it's because I'm inheriting from Control rather than UserControl or
Panel?