473,324 Members | 2,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Painting of custom control slow

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
5 15031
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

"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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bill K | last post by:
I am developing a winforms project in vb.net. I have several forms that have a number of controls, grids, etc. When I load these as MDI child forms, they load slowly AND they paint/repaint on the...
2
by: Robert Misiak | last post by:
Hi everyone- I've done a lot of searching around on the web and I'm sure the answer to this question is no, but I'll ask anyway. Is it possible to create an inherited MonthCalendar control and...
0
by: Simon Prince | last post by:
Hi I have created a .NET "Windows Custom Control" which is used an ASPX Web Form. It is referenced with the code, from a ASPX page. **************************************************...
2
by: Carl Gilbert | last post by:
Hi I am developing a custom on screen keyboard. So far I have an array of buttons and then using SendKeys to send the text of the button to the active control to receive the text. The only...
0
by: J Rico | last post by:
Hi, I'm having a problem with some code we're writting. Our customer doesn't like windows forms style painting, so their designer has created a skin and we have added it. There are many ways in...
2
by: Peteroid | last post by:
When the application I'm working on is run it creates a panel with a Paint event customized to draw primitives (circles, rectangles, etc.), places the panel on a form, and then launches the form....
0
by: Litani | last post by:
Hi everyone, We have a winform application that uses webservices. It has list screens. The user selects a row from the grid and an edit screen is presented to the user with the selected row. ...
1
by: Brendon Bezuidenhout | last post by:
Evening, I have a slight erk with the ComboBoxRenderer running under Vista and was hoping someone could shed some light on this for me. I've created a custom control that inherits from Button...
5
by: lazyvlad | last post by:
Hi, I'm writing here because this issue is becoming more annoying with each day it passes. So I have a form, a dataset with a few table adapters (3 to be precise) and a datagridview.The datagridview...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.