Solved

Alternative to paint event

Posted on 2004-09-04
7
417 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

786 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