Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. smooth motion

smooth motion

Scheduled Pinned Locked Moved Visual Basic
question
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TheMrProgrammer
    wrote on last edited by
    #1

    hi all genius people! my app has picture boxes or labels moving through the whole form in various directions. to do this i am placing the code below to a timer of interval = 1 ms pic1.left += some constant pic1.top += some constant when this constant is 1 the motion is quite smooth but when this constant has a larger value say 5 then the motion is rough i tried using loops like this and placing it in the same timer for x = 1 to 5 pic1.left += 1 pic1.top += 1 next x but as my app has many pic boxes and this timer runs for about 2 mins (=2*60*60*1000 ms) this takes a lot of cpu any ideas?? my sole intention is to make the motion smooth thankx

    TheMrProgrammer

    D 1 Reply Last reply
    0
    • T TheMrProgrammer

      hi all genius people! my app has picture boxes or labels moving through the whole form in various directions. to do this i am placing the code below to a timer of interval = 1 ms pic1.left += some constant pic1.top += some constant when this constant is 1 the motion is quite smooth but when this constant has a larger value say 5 then the motion is rough i tried using loops like this and placing it in the same timer for x = 1 to 5 pic1.left += 1 pic1.top += 1 next x but as my app has many pic boxes and this timer runs for about 2 mins (=2*60*60*1000 ms) this takes a lot of cpu any ideas?? my sole intention is to make the motion smooth thankx

      TheMrProgrammer

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      The only way you're going to get smooth motion is to stop using controls to render all of your content, and even then, you might not get what you want, but it'll be a VAST improvement. You have to handle the Paint event of your form and draw all of your content yourself. Controls are too expensive to redraw and, from what I see if your small code snippet, you're not giving the form any time to redraw the controls in a timely fashion.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008

      T 1 Reply Last reply
      0
      • D Dave Kreskowiak

        The only way you're going to get smooth motion is to stop using controls to render all of your content, and even then, you might not get what you want, but it'll be a VAST improvement. You have to handle the Paint event of your form and draw all of your content yourself. Controls are too expensive to redraw and, from what I see if your small code snippet, you're not giving the form any time to redraw the controls in a timely fashion.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

        T Offline
        T Offline
        TheMrProgrammer
        wrote on last edited by
        #3

        so you suggest to drop all the controls and stick to graphics object? and/or i should increase the interval of the timer? to maybe 10 ms or what?

        TheMrProgrammer

        L 1 Reply Last reply
        0
        • T TheMrProgrammer

          so you suggest to drop all the controls and stick to graphics object? and/or i should increase the interval of the timer? to maybe 10 ms or what?

          TheMrProgrammer

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi, 1. a simple timer will not provide small steps such as 1 msec (see my timers article for details). 2. you don't need such small times anyway; a movie is built with some 24 frames per second, that is 40 msec per frame. 3. you do need double-buffering, so you don't see the building-up of each frame. 4. As Dave said, get rid of the Controls, paint it all to a single Panel. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups