|
-
Jul 6th, 2009, 12:24 PM
#1
Thread Starter
Member
Moving image from left to rignt like marque in C#.net
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
-
Jul 6th, 2009, 08:09 PM
#2
Re: Moving image from left to rignt like marque in C#.net
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.
-
Jul 8th, 2009, 04:50 AM
#3
Thread Starter
Member
Re: Moving image from left to rignt like marque in C#.net
 Originally Posted by jmcilhinney
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.
Hi,
Can u plz provide a code snippet for it, as i m new to C#.net.
Thnks and Regards,
V'jay
-
Jul 8th, 2009, 05:11 AM
#4
Re: Moving image from left to rignt like marque in C#.net
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.
-
Jul 8th, 2009, 09:29 AM
#5
Hyperactive Member
Re: Moving image from left to rignt like marque in C#.net
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);
If I helped you please rate me.
-
Jul 14th, 2009, 01:15 PM
#6
Thread Starter
Member
Re: Moving image from left to rignt like marque in C#.net
thnks dude, code working fine...............
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
|