473,776 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(Ima ge 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 15126
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(Contro lStyles.UserPai nt, true);
SetStyle(Contro lStyles.AllPain tingInWmPaint, true);
SetStyle(Contro lStyles.DoubleB uffer, true);
//
// Required for Windows Form Designer support
//
InitializeCompo nent();

}
HTH,
Jon
"Alien" <al***@sympatic o.ca> wrote in message
news:Gk******** **********@news 01.bloor.is.net .cable.rogers.c om...
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(Ima ge 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.c om> wrote in message
news:22******** *************** **@posting.goog le.com...
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******** ******@TK2MSFTN GP12.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(Contro lStyles.UserPai nt, true);
SetStyle(Contro lStyles.AllPain tingInWmPaint, true);
SetStyle(Contro lStyles.DoubleB uffer, true);
//
// Required for Windows Form Designer support
//
InitializeCompo nent();

}
HTH,
Jon
"Alien" <al***@sympatic o.ca> wrote in message
news:Gk******** **********@news 01.bloor.is.net .cable.rogers.c om...
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(Ima ge 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.c om> wrote in message
news:22******** *************** **@posting.goog le.com...
"Alien" <al***@sympatic o.ca> wrote in message news:<Gk******* ***********@new s01.bloor.is.ne t.cable.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(Ima ge 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***@sympatic o.ca> wrote in message
news:VT******** *********@news0 2.bloor.is.net. cable.rogers.co m...
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******** ******@TK2MSFTN GP12.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(Contro lStyles.UserPai nt, true);
SetStyle(Contro lStyles.AllPain tingInWmPaint, true);
SetStyle(Contro lStyles.DoubleB uffer, true);
//
// Required for Windows Form Designer support
//
InitializeCompo nent();

}
HTH,
Jon
"Alien" <al***@sympatic o.ca> wrote in message
news:Gk******** **********@news 01.bloor.is.net .cable.rogers.c om...
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(Ima ge 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
2239
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 screen, and it makes a sloppy presentation. I am unhappy with it, and obviously the client says that it is unacceptable. How can I make a nice, crisp form/screen opening? Thanks so much for you help.
2
5115
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 override the member that paints the background? I've tried working with OnPaint, OnPaintBackground to no avail. Perhaps someone has a similar calendar control implementation out there? Thanks, Robert
0
1036
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. ************************************************** <object id="myComponent" classid="http:#"
2
1806
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 problem is that the application is rather slow at painting the buttons. Ideally I wanted to allow the user to re-size the control and change the text and style of the buttons without such rendering issues. (I have a tool to re-size the buttons,...
0
907
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 doing this, so it hasn't been a great problem. The problem is when those forms, which are ChildForms in an MDI, get minimized. I have no idea in how repainting the minimized form. I've tried many things, and cannot paint by myself the minimized...
2
2170
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. The weird part is, the panel, in the instant it becomes visible, seems to have an image of what this panel had in it the LAST TIME THE APPLICATION WAS RUN! Since this panel is created anew every time the application is run ('natch), this seems...
0
1278
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. Switching from the list screen to edit is slow if I have decent amount of controls. I can see the screen painting. In some cases, I can see the application painting some controls read only or disabled. Any suggestions on how to display the...
1
2770
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 - no problems there :) The problem comes with the actual painting of the custom button... The Visa one blends in almost perfectly with the textbox component of a combo - BUT a
5
4248
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 has a lot of columns as checkboxes (30 columns are checkboxes per row). The problem is in the form drawing and painting, when first shown the form paints itself very slow and im running this on a relatively powerful computer (Pentium 2.4GHz with...
0
9464
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10292
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8954
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7471
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5368
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.