日期:2014-05-17  浏览次数:20848 次

C#--第11周实验--任务9(设计一个窗体)--利用Timer和图片框控件,编写一个图片不断向左移动的小动画
/* (程序头部注释开始)  
 * 程序的版权和版本声明部分  
 * Copyright (c) 2011, 烟台大学计算机学院学生   
 * All rights reserved.  
 * 文件名称:利用Timer和图片框控件,编写一个图片不断向左移动的小动画。
 * 作 者: 雷恒鑫   
 * 完成日期: 2012 年 11 月 10 日  
 * 版 本 号: V1.0   
 * 对任务及求解方法的描述部分  
 * 输入描述:利用Timer和图片框控件,编写一个图片不断向左移动的小动画。
 * 问题描述:  
 * 程序输出:  
 * 程序头部的注释结束  
 */


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication_twelve
{
    public partial class Form1 : Form
    {
        Boolean b = true;
        private int startY = 0, startY1 = 0, startY2 = 0;

        public Form1()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
            //this.FormBorderStyle = FormBorderStyle.FixedSingle;

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Text = "图片框实验";
            this.StartPosition = FormStartPosition.CenterScreen;
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            pictureBox1.Image = Image.FromFile("lanyangyang_one.png");
            pictureBox2.Image = Image.FromFile("qingwa_one.png");
            pictureBox3.Image = Image.FromFile("xiaopohai_one.png");

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            int i = pictureBox1.Location.X + 10;
            int i2 = pictureBox2.Location.X + 10;
            int i3 = pictureBox3.Location.X + 10;
            if (i > this.Width)
            {
                i = 0;
            }
            startY = pictureBox1.Location.Y;
            startY1 = pictureBox2.Location.Y;
            startY2 = pictureBox3.Location.Y;
            pictureBox1.Location = new Point(i, startY);
            pictureBox1.Refresh();
            pictureBox2.Location = new Point(i, startY1);
            pictureBox2.Refresh();
            pictureBox3.Location = new Point(i, startY2);

            pictureBox2.Refresh();
            pictureBox3.Refresh();
        }

    }
}


 

运行结果: