Results 1 to 6 of 6

Thread: Moving image from left to rignt like marque in C#.net

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2008
    Posts
    60

    Angry 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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2008
    Posts
    60

    Re: Moving image from left to rignt like marque in C#.net

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

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Hyperactive Member
    Join Date
    Jan 2009
    Posts
    448

    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.

  6. #6

    Thread Starter
    Member
    Join Date
    Dec 2008
    Posts
    60

    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
  •  



Click Here to Expand Forum to Full Width