A
Alex Clark
Hi,
I'm trying to improve the painting performance of a control on my form.
The scenario is this - I have a custom control which inherits from Control,
and I manually paint the entire GUI for it. The GUI is fairly static, so
once I've drawn the appropriate image, I cache that to an Image object and
re-use that.
My code snippet is as follows:
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
e.Graphics.DrawImage(_displayImage, e.ClipRectangle, e.ClipRectangle,
GraphicsUnit.Pixel)
End Sub
Where _displayImage is the cached Image object.
Performance absolutely blows. It's fine to initially paint the screen, but
if I (for example) load up an instance of calculator and drag it over my
application, repainting of these controls is incredibly slow. I can
literally saturate the GUI of my app (when it's covered with these custom
controls) with ghostly trails of the calculator window. Once I stop
dragging the calc window, *then* my controls seem to update.
Is there some smarter solution? I've tried using Graphics.DrawImageUnscaled
but it seems to have no effect on performance. My control is set to
DoubleBuffer, UserPaint, and AllPaintingInWMPaint. I'm surprised that this
isn't faster, as all I'm doing is drawing an in-memory bitmap to the screen.
I'm even using clipping so that it should only repaint the affected area.
Why so slow? :-(
Thanks,
Alex
I'm trying to improve the painting performance of a control on my form.
The scenario is this - I have a custom control which inherits from Control,
and I manually paint the entire GUI for it. The GUI is fairly static, so
once I've drawn the appropriate image, I cache that to an Image object and
re-use that.
My code snippet is as follows:
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
e.Graphics.DrawImage(_displayImage, e.ClipRectangle, e.ClipRectangle,
GraphicsUnit.Pixel)
End Sub
Where _displayImage is the cached Image object.
Performance absolutely blows. It's fine to initially paint the screen, but
if I (for example) load up an instance of calculator and drag it over my
application, repainting of these controls is incredibly slow. I can
literally saturate the GUI of my app (when it's covered with these custom
controls) with ghostly trails of the calculator window. Once I stop
dragging the calc window, *then* my controls seem to update.
Is there some smarter solution? I've tried using Graphics.DrawImageUnscaled
but it seems to have no effect on performance. My control is set to
DoubleBuffer, UserPaint, and AllPaintingInWMPaint. I'm surprised that this
isn't faster, as all I'm doing is drawing an in-memory bitmap to the screen.
I'm even using clipping so that it should only repaint the affected area.
Why so slow? :-(
Thanks,
Alex