Solved

Alternative to paint event

Posted on 2004-09-04
7
421 Views
Last Modified: 2010-05-18
My project deals with huge number of lines (millions) drawn on a picture box. The problem is when the picture box is refreshed (eg. while minimizing-maximizing the form) it takes some time for the lines to appear on the form. In VB 6 the action is instantaneous setting autoredraw property to true. In VB.net however it takes quite some time, and the time is directly proportional to the number of lines.

I have tried keeping only the draw functions in the paint event, i.e. excluded all the mathematical functions from the paint event, yet it didn't help much.

Can anyone sugest an alternative to this approach.. .or other tips to improve the performance. By the way instead of Refresh method, i have also tried using invalidate.. that doesn't help either.  
0
Comment
Question by:prince_wow
  • 3
  • 3
7 Comments
 
LVL 4

Expert Comment

by:Javert93
ID: 12008543
Unfortunately, there is no alternative to using the Paint() event if you want to draw to the picture box. VB.NET no longer stores the rendered image, so there is no "AutoRedaw()" property to set. The Win32 API contain a lot of nifty functions that may speed up the painting process, and you can use the ClipRectangle property of the EventArgs object to limit your drawing scope, but I'm afraid you're stuck with the Paint() event.
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 63 total points
ID: 12008764
If you are calculating your lines based on some parameters, then do the calculations once, and store them in a GraphicsPath instance.  Then, if your parameters haven't changed, you can simply redraw the GraphicsPath when the Paint event fires which should be faster than calculating them again.  If your parameters have changed, then you can recalculate the new lines and store them in a new GraphicsPath.

The tradeoff here is memory for speed.  Storing "millions" of lines in a GraphicsPath may not be feasible.

Regards,

Idle_Mind
0
 

Author Comment

by:prince_wow
ID: 12023497
Thanks Javert93 and Ideal_Mind.. With VB .net it seems it is impossible to make my application faster. As you said Ideal_mind I haven't included any calculation while redrawing..

I am trying to convert my current project in VB to VB.net for faster performance.. but I guess the conversion doesn't worth it. One more problem I am facing is User-defined Scale..  My application gets the Scale information from the binary file, and the graphics is drawn accordingly.. but in VB.net everything is in pixels, there is no userdefined Scale... I need to do the manual calculation of the scale for each and every drawing. With that while considering millions of lines the application becomes darn slow..

I am at the starting phase of conversion.. so can you guys suggest what alternative I might have for VB.net - slick and faster.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 4

Accepted Solution

by:
Javert93 earned 62 total points
ID: 12023559
You could use C++ managed extensions. You get the flexability of native C++ with the added benefit of being able to use the framework classes where and when you actually want them. C# is a close second, but only because it allows unmanged code blocks.
0
 

Author Comment

by:prince_wow
ID: 12023835
I haven't done much of Graphics in C++ or C#... can you suggest some websites that I can look in.
0
 
LVL 4

Expert Comment

by:Javert93
ID: 12028617
I don't know of any offhand for C++, but http://www.gotdotnet.com and http://www.thecodeproject.com are good resources for C#.
0
 

Author Comment

by:prince_wow
ID: 12036761
Thanks Javert93
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question