20181217-runner-1

int num=0;

int flag = 1; // 1代表往左邊跑 -1代表往右邊跑

public Form1()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{

pictureBox1.Image = imageList1.Images[0];

pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;

timer1.Enabled = true;

timer1.Interval = 100;

timer2.Enabled = true;

timer2.Interval = 50;

}

private void timer1_Tick(object sender, EventArgs e)

{

// num from 0 to 3

pictureBox1.Image = imageList1.Images[num]; // 顯示第num張圖

if(flag == -1)

pictureBox1.Image.RotateFlip(RotateFlipType.Rotate180FlipY);

if (num == 3) //若圖片註標值 = 3

num = 0; //設圖片註標值 = 0

else //其餘即圖片註標值 < 3

num++; //圖片註標值加 1

}

private void timer2_Tick(object sender, EventArgs e)

{

pictureBox1.Left -= flag*10; //當flag =1時, 每次都減10 往左------當flag =-1時, 每次都加10 往右

if (pictureBox1.Left <= -45)

flag = -1 * flag; //跑步反向

if (pictureBox1.Left >= this.ClientSize.Width)

flag = -1 * flag; //跑步反向

//pictureBox1.Left = 400;

//pictureBox1.Left = this.ClientSize.Width;

}