in VB.Net, I have a picturebox containing a graph like picture that looks like a grid. There are also various code drawn shapes in the picturebox that can be clicked by the user.. I'm trying to figure out a way of having a vertical line from top to bottom of the picturebox that moves across from left to right at a predetermined speed. I also need to able to determine when the line moved across a shape that he been clicked. Any suggestions would be appreciated. Many thanks.
I've solved the other problems mentioned and can produce a vertical line in the picturebox with simple code. But I'm stuck on trying to animate the line.
Here is an example of a vertical line that moves from left to right and starts again once it makes a full pass:
The X coordinate of the line is stored in a field and that field is incremented on each
Tickevent of theTimer. The value is reset to zero once it reaches the right side of thePictureBox.It's up to you what you set the
Intervalof theTimerto. A smaller value will obviously move the line faster. You can also vary the amount by which you increment the X coordinate. A smaller value will lead to a smoother animation. You'll need to balance those two values to get the speed and smoothness you want while not interfering noticeably with any other GUI operations.Generally speaking, it is preferable to calculate the smallest area that may have changed on the control and specify that when you call
Invalidate. The entire code in thePaintevent handler is still executed but only the pixels within that area are repainted on screen and it's that last step that is the slowest part. I'll leave that as an exercise for you though. You would need to create the smallestRectanglethat contained both the old line and the new line so that area was repainted, erasing the old line and drawing the new line. At the point that the line reset to the left side, you could invalidate the whole control or you could callInvalidatetwice - once for the old line on the right and once for the new line on the left. You can callInvalidateas many times as you like to repaint complex areas.