Making screensavers, Moving pictures

Source: Internet
Author: User

Public partial class Imagemove:form
    {
Public imagemove ()
        {
InitializeComponent ();
        }

int x = 1;//x to 1 for horizontal to right, 1 for horizontal to left
int y = 1;//y is 1 for vertical downward movement, 1 for vertical upward movement
int move = 5;//The distance between each move, horizontal and vertical are the same
private void Timer1_Tick (object sender, EventArgs e)
        {
//Set the position of the picture according to the X value
if (x = = 1)
            {
This.pictureBox1.Left + = move;
            }
Else
            {
This.pictureBox1.Left-= move;
                
            }
//Set picture position according to Y value
if (y = = 1)
            {
This.pictureBox1.Top + = move;
            }
Else
            {
This.pictureBox1.Top-= move;
            }

//Horizontal Direction
//Hit the right (minus 20 mainly considering that the form has a border)
if (x==1&&this.picturebox1.left+this.picturebox1.width>=this. WIDTH-20)
            {
x =-1;
            }
//Hit the left
else if (x = =-1 && this.pictureBox1.Left <= 0)
            {
x = 1;
            }

//Vertical Direction
//Hit the end (37 represents the height of the title bar)
if (y==1&&this.picturebox1.top+this.picturebox1.height>= this. HEIGHT-37)
            {
y =-1;
            }
//Hit the top
else if (y==-1&&this.picturebox1.top <= 0)
            {
y = 1;
            }

        }
    }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.