* Copyright (c) 2012, 烟台大学计算机学院学生
* All rights reserved.
* 作 者: 刘镇
* 完成日期: 2012 年 11 月 10 日
* 版 本 号: 3.021
* 对任务及求解方法的描述部分
* 问题描述:
利用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 win9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
Point p = pictureBox1.Location;
if (pictureBox1.Location.X != 460)
{
p.X++;
}
else
{
p.X = 0;
}
pictureBox1.Location = p;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Start();
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Stop();
timer1.Dispose();
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
测试结果;
心得经验:
一、难题就是直接改变图片的位置Location是按不到的,Location不是可以调用的方法;因此可以通过引入Point座标点类,用来修改Location,然后就是将Timer的Tick事件加以处理,让他按指定时间间隔移动点的座标。