By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,257 Members | 928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,257 IT Pros & Developers. It's quick & easy.

Painting of custom control slow

P: n/a
I have a hex editor-type class that extends UserControl and paints its data
to a PictureBox. Basically the problem is that repainting it takes usually
between 60 and 80ms, which may seem pretty fast but is not good enough when
you have to repaint very frequently. For example, when you scroll the
control or select blocks of text quickly.

I have it paint its graphics to an offscreen Graphics instance, which I then
transfer to the PictureBox using g.DrawImage(Image m, int x, int y)...
Making it paint directly onto the PictureBox is (understandably) even
slower.

So, is there anything I can do to improve the situation or am I stuck? I'm
on a 1.4ghz Athlon by the way.
Thanks

Nov 15 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
I've done only a small amount of System.Drawing work, but I think I can
still make a suggestion: Don't paint anything that hasn't changed. When a
form is updated for painting, find the region that is being repainted, then
repaint only that region. A little 32x32 square or even a skinny 2x500
rectangle will paint much faster than a massive 640x480 area.

Also, be sure you're double-buffering, to eliminate the flicker ...

public MyControl()
{

// Activates double buffering
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
//
// Required for Windows Form Designer support
//
InitializeComponent();

}
HTH,
Jon
"Alien" <al***@sympatico.ca> wrote in message
news:Gk******************@news01.bloor.is.net.cabl e.rogers.com...
I have a hex editor-type class that extends UserControl and paints its data to a PictureBox. Basically the problem is that repainting it takes usually
between 60 and 80ms, which may seem pretty fast but is not good enough when you have to repaint very frequently. For example, when you scroll the
control or select blocks of text quickly.

I have it paint its graphics to an offscreen Graphics instance, which I then transfer to the PictureBox using g.DrawImage(Image m, int x, int y)...
Making it paint directly onto the PictureBox is (understandably) even
slower.

So, is there anything I can do to improve the situation or am I stuck? I'm
on a 1.4ghz Athlon by the way.
Thanks

Nov 15 '05 #2

P: n/a

"Lucean Morningside" <m@exquisitor.com> wrote in message
news:22*************************@posting.google.co m...
You can use Compuware's DevPartner Profiler
Community Edition, which can be found at:
http://www.compuware.com/products/de...er/default.asp

Hope this helps.

-LM

Ever tried ANTS? I was considering looking into that... Any good? How does
it compare with Compuware?

Jon
Nov 15 '05 #3

P: n/a
Thanks for your help

I am double-buffering, though not using the SetStyle method. Painting only
the regions that have changed can get a bit tricky in a textbox, but I
should probably give it a try. However, it does not solve my main problem..
When the control is scrolled, everything changes, so I'll have to repaint
the entire control anyway.

I'm now trying to use GDI API functions instead of the wrappers (GDI+) .NET
provides, and in my experimenting they are a bit faster (repaint time down
to 40-50ms, and if I turn off double-buffering, 10-20ms).

"Jon Davis" <jo*@REMOVE.ME.PLEASE.jondavis.net> wrote in message
news:el**************@TK2MSFTNGP12.phx.gbl...
I've done only a small amount of System.Drawing work, but I think I can
still make a suggestion: Don't paint anything that hasn't changed. When a
form is updated for painting, find the region that is being repainted, then repaint only that region. A little 32x32 square or even a skinny 2x500
rectangle will paint much faster than a massive 640x480 area.

Also, be sure you're double-buffering, to eliminate the flicker ...

public MyControl()
{

// Activates double buffering
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
//
// Required for Windows Form Designer support
//
InitializeComponent();

}
HTH,
Jon
"Alien" <al***@sympatico.ca> wrote in message
news:Gk******************@news01.bloor.is.net.cabl e.rogers.com...
I have a hex editor-type class that extends UserControl and paints its

data
to a PictureBox. Basically the problem is that repainting it takes usually between 60 and 80ms, which may seem pretty fast but is not good enough

when
you have to repaint very frequently. For example, when you scroll the
control or select blocks of text quickly.

I have it paint its graphics to an offscreen Graphics instance, which I

then
transfer to the PictureBox using g.DrawImage(Image m, int x, int y)...
Making it paint directly onto the PictureBox is (understandably) even
slower.

So, is there anything I can do to improve the situation or am I stuck? I'm on a 1.4ghz Athlon by the way.
Thanks


Nov 15 '05 #4

P: n/a
Thanks for the link Lucean, I'll check it out.

"Lucean Morningside" <m@exquisitor.com> wrote in message
news:22*************************@posting.google.co m...
"Alien" <al***@sympatico.ca> wrote in message news:<Gk******************@news01.bloor.is.net.cab le.rogers.com>...
I have a hex editor-type class that extends UserControl and paints its data to a PictureBox. Basically the problem is that repainting it takes usually between 60 and 80ms, which may seem pretty fast but is not good enough when you have to repaint very frequently. For example, when you scroll the
control or select blocks of text quickly.

I have it paint its graphics to an offscreen Graphics instance, which I then transfer to the PictureBox using g.DrawImage(Image m, int x, int y)...
Making it paint directly onto the PictureBox is (understandably) even
slower.

So, is there anything I can do to improve the situation or am I stuck? I'm on a 1.4ghz Athlon by the way.
Thanks


There's only one thing that you can do: profile your code to find all
performance bottlenecks. I ran into a similar performance problem once

when I was writing a fractal image compression and decompression program. I tried to blindly optimize the code, but I never got any real performance increase. Not until I ran my code through a profiler. Only then was I able to locate the exact methods that needed optimization. You can use Compuware's DevPartner Profiler Community Edition, which can be found at:
http://www.compuware.com/products/de...er/default.asp

Hope this helps.

-LM

Nov 15 '05 #5

P: n/a
Heh, well.. I can get it to hover around 10ms (even drop to 7 or 8
sometimes) with double-buffering turned off and using raw GDI calls, but
with double-buffering it's still noticeably sluggish.

So it's a trade-off between flickering like hell or slow repaint.

"Alien" <al***@sympatico.ca> wrote in message
news:VT*****************@news02.bloor.is.net.cable .rogers.com...
Thanks for your help

I am double-buffering, though not using the SetStyle method. Painting only
the regions that have changed can get a bit tricky in a textbox, but I
should probably give it a try. However, it does not solve my main problem.. When the control is scrolled, everything changes, so I'll have to repaint
the entire control anyway.

I'm now trying to use GDI API functions instead of the wrappers (GDI+) ..NET provides, and in my experimenting they are a bit faster (repaint time down
to 40-50ms, and if I turn off double-buffering, 10-20ms).

"Jon Davis" <jo*@REMOVE.ME.PLEASE.jondavis.net> wrote in message
news:el**************@TK2MSFTNGP12.phx.gbl...
I've done only a small amount of System.Drawing work, but I think I can
still make a suggestion: Don't paint anything that hasn't changed. When a
form is updated for painting, find the region that is being repainted,

then
repaint only that region. A little 32x32 square or even a skinny 2x500
rectangle will paint much faster than a massive 640x480 area.

Also, be sure you're double-buffering, to eliminate the flicker ...

public MyControl()
{

// Activates double buffering
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
//
// Required for Windows Form Designer support
//
InitializeComponent();

}
HTH,
Jon
"Alien" <al***@sympatico.ca> wrote in message
news:Gk******************@news01.bloor.is.net.cabl e.rogers.com...
I have a hex editor-type class that extends UserControl and paints its

data
to a PictureBox. Basically the problem is that repainting it takes usually between 60 and 80ms, which may seem pretty fast but is not good enough

when
you have to repaint very frequently. For example, when you scroll the
control or select blocks of text quickly.

I have it paint its graphics to an offscreen Graphics instance, which
I then
transfer to the PictureBox using g.DrawImage(Image m, int x, int y)...
Making it paint directly onto the PictureBox is (understandably) even
slower.

So, is there anything I can do to improve the situation or am I stuck?

I'm on a 1.4ghz Athlon by the way.
Thanks



Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.