Solved

Alternative to paint event

Posted on 2004-09-04
7
423 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

679 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