Connecting Tech Pros Worldwide Help | Site Map

Painting of custom control slow

Alien
Guest
 
Posts: n/a
#1: Nov 15 '05
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



Jon Davis
Guest
 
Posts: n/a
#2: Nov 15 '05

re: Painting of custom control slow


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" <alien@sympatico.ca> wrote in message
news:GkkSa.6265$PJF1.4991@news01.bloor.is.net.cabl e.rogers.com...[color=blue]
> I have a hex editor-type class that extends UserControl and paints its[/color]
data[color=blue]
> 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[/color]
when[color=blue]
> 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[/color]
then[color=blue]
> 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
>
>
>[/color]


Jon Davis
Guest
 
Posts: n/a
#3: Nov 15 '05

re: Painting of custom control slow



"Lucean Morningside" <m@exquisitor.com> wrote in message
news:223a495.0307192227.6fdb459d@posting.google.co m...[color=blue]
> 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[/color]


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

Jon


Alien
Guest
 
Posts: n/a
#4: Nov 15 '05

re: Painting of custom control slow


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" <jon@REMOVE.ME.PLEASE.jondavis.net> wrote in message
news:elVQf9nTDHA.2324@TK2MSFTNGP12.phx.gbl...[color=blue]
> 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,[/color]
then[color=blue]
> 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" <alien@sympatico.ca> wrote in message
> news:GkkSa.6265$PJF1.4991@news01.bloor.is.net.cabl e.rogers.com...[color=green]
> > I have a hex editor-type class that extends UserControl and paints its[/color]
> data[color=green]
> > to a PictureBox. Basically the problem is that repainting it takes[/color][/color]
usually[color=blue][color=green]
> > between 60 and 80ms, which may seem pretty fast but is not good enough[/color]
> when[color=green]
> > 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[/color]
> then[color=green]
> > 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?[/color][/color]
I'm[color=blue][color=green]
> > on a 1.4ghz Athlon by the way.
> >
> >
> > Thanks
> >
> >
> >[/color]
>
>[/color]


Alien
Guest
 
Posts: n/a
#5: Nov 15 '05

re: Painting of custom control slow


Thanks for the link Lucean, I'll check it out.

"Lucean Morningside" <m@exquisitor.com> wrote in message
news:223a495.0307192227.6fdb459d@posting.google.co m...[color=blue]
> "Alien" <alien@sympatico.ca> wrote in message[/color]
news:<GkkSa.6265$PJF1.4991@news01.bloor.is.net.cab le.rogers.com>...[color=blue][color=green]
> > I have a hex editor-type class that extends UserControl and paints its[/color][/color]
data[color=blue][color=green]
> > to a PictureBox. Basically the problem is that repainting it takes[/color][/color]
usually[color=blue][color=green]
> > between 60 and 80ms, which may seem pretty fast but is not good enough[/color][/color]
when[color=blue][color=green]
> > 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[/color][/color]
then[color=blue][color=green]
> > 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?[/color][/color]
I'm[color=blue][color=green]
> > on a 1.4ghz Athlon by the way.
> >
> >
> > Thanks[/color]
>
> 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[/color]
when[color=blue]
> I was writing a fractal image compression and decompression program. I[/color]
tried[color=blue]
> to blindly optimize the code, but I never got any real performance[/color]
increase. Not[color=blue]
> until I ran my code through a profiler. Only then was I able to locate the[/color]
exact[color=blue]
> methods that needed optimization. You can use Compuware's DevPartner[/color]
Profiler[color=blue]
> Community Edition, which can be found at:
> http://www.compuware.com/products/de...er/default.asp
>
> Hope this helps.
>
> -LM[/color]


Alien
Guest
 
Posts: n/a
#6: Nov 15 '05

re: Painting of custom control slow


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" <alien@sympatico.ca> wrote in message
news:VTqSa.8043$2h1.3461@news02.bloor.is.net.cable .rogers.com...[color=blue]
> 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[/color]
problem..[color=blue]
> 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+)[/color]
..NET[color=blue]
> 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" <jon@REMOVE.ME.PLEASE.jondavis.net> wrote in message
> news:elVQf9nTDHA.2324@TK2MSFTNGP12.phx.gbl...[color=green]
> > 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[/color][/color]
a[color=blue][color=green]
> > form is updated for painting, find the region that is being repainted,[/color]
> then[color=green]
> > 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" <alien@sympatico.ca> wrote in message
> > news:GkkSa.6265$PJF1.4991@news01.bloor.is.net.cabl e.rogers.com...[color=darkred]
> > > I have a hex editor-type class that extends UserControl and paints its[/color]
> > data[color=darkred]
> > > to a PictureBox. Basically the problem is that repainting it takes[/color][/color]
> usually[color=green][color=darkred]
> > > between 60 and 80ms, which may seem pretty fast but is not good enough[/color]
> > when[color=darkred]
> > > 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[/color][/color][/color]
I[color=blue][color=green]
> > then[color=darkred]
> > > 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?[/color][/color]
> I'm[color=green][color=darkred]
> > > on a 1.4ghz Athlon by the way.
> > >
> > >
> > > Thanks
> > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Closed Thread