Results 1 to 5 of 5

Thread: Fast Grid Layout

  1. #1

    Thread Starter
    Lively Member arithmetica's Avatar
    Join Date
    Jan 2009
    Location
    Ahvaz, Iran
    Posts
    89

    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!

  2. #2
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    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.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  3. #3
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Fast Grid Layout

    Quote Originally Posted by Jenner View Post
    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

  4. #4
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    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.
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  5. #5

    Thread Starter
    Lively Member arithmetica's Avatar
    Join Date
    Jan 2009
    Location
    Ahvaz, Iran
    Posts
    89

    Resolved 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
  •  



Click Here to Expand Forum to Full Width