|
-
Jul 2nd, 2009, 01:37 PM
#1
Thread Starter
Lively Member
Fast Grid Layout
Hello everyone,
I'm trying to make grids in a picturebox in order to be able to draw some charts on it. I use the following code but it takes a lot of time to draw the grids in each frame. What can one do to make drawing of grids faster?
Code:
Pic.Scale (0, Pic.ScaleHeight)-(Pic.ScaleWidth, 0)
Dim i As Integer, j As Integer
For i = 0 To Int((Pic.ScaleWidth) * 0.1)
For j = 0 To Int((Pic.ScaleTop) * 0.1)
Pic.Line ((i) * 10, 0)-((i) * 10, Pic.ScaleTop), vbBlue
Pic.Line (0, (j) * 10)-(Pic.ScaleWidth, (j) * 10), vbBlue
Next j
Next i
Thanks for your help!
-
Jul 2nd, 2009, 02:47 PM
#2
Re: Fast Grid Layout
Overriding the OnPaint event would yield faster results. Your code would be very similar as well. You wouldn't do it on a PictureBox though. Most advanced graphics techniques start off with throwing away all the useless controls like PictureBoxes and draw directly on the form.
-
Jul 2nd, 2009, 08:14 PM
#3
Re: Fast Grid Layout
 Originally Posted by Jenner
Overriding the OnPaint event would yield faster results. Your code would be very similar as well. You wouldn't do it on a PictureBox though. Most advanced graphics techniques start off with throwing away all the useless controls like PictureBoxes and draw directly on the form.
This is written in VB6..
You will need to look at the GetDIBits and SetDIBits APIs. If you are unsure how to use APIs, then you won't get anything faster.
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Jul 2nd, 2009, 11:17 PM
#4
Fanatic Member
Re: Fast Grid Layout
Why are you redrawing the grid in every frame. Draw the grid once and draw over it.
Several ways to do this without resorting to API calls.
1. Set autoredraw to true draw your grid then set autoredraw to false. To redraw the background with grid pic.refresh. Then you can draw the foreground lines over it.
2. Draw the grid into an invisible picturebox with autoredraw set to true. then to update your graph use paintpicture to draw background before you draw foreground
3. Use line controls for plotting they will overlay over the grid - the pic box will be their parent so they'll use the grids coordinate scale.
Last edited by technorobbo; Jul 2nd, 2009 at 11:22 PM.
-
Jul 3rd, 2009, 03:34 AM
#5
Thread Starter
Lively Member
Re: Fast Grid Layout
Thanks a lot technorobo! The first way works for me!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|