Hi 2 all,
I need a code snippet for moving image from left to right continuously in C#.net. Please help me out from this.
Thanks and regards,
V'jay
Printable View
Hi 2 all,
I need a code snippet for moving image from left to right continuously in C#.net. Please help me out from this.
Thanks and regards,
V'jay
Add a Timer to your form and increment the Left property of your PictureBox in its Tick event handler. Once it gets to the rightmost extremity you set it back to the leftmost extremity.
The smaller the increments the smoother the motion but the slower the movement, so the smaller Interval you would need to use with your Timer. Larger Intervals are better from a performance perspective so you should experiment to find the right balance.
Follow the CodeBank link in my signature and check out the Scrolling Text thread. You can do essentially the same thing with a PictureBox as I do with a Label there.
You could do this in a timers tick event. Make sure that the timer is enabled and declare an "int SPEED = 5;" outside of the tick event:
Code:/*set the picturebox width and height to the
images width and height so it is more accurate
*/
pictureBox1.Width = pictureBox1.Image.Width;
pictureBox1.Height = pictureBox1.Image.Height;
//set the x and y of the picturebox
int x = pictureBox1.Left;
int y = pictureBox1.Top;
//check if the picturebox is going off the form on right or left
if (pictureBox1.Location.X + pictureBox1.Width > this.Width || pictureBox1.Location.X < 0)
{
SPEED *= -1;
}
//set the picturebox's location
pictureBox1.Location = new Point(x + SPEED , y);
thnks dude, code working fine...............