您的位置:首页 > 其它

使用timer控件演示简单动画程序

2007-11-06 14:03 549 查看


是一个Gif动画 显示过程是从左到右的运动,运到到最后又返回来从左面重新出现继续向右运动!

代码如下(设置timer控件的interval属性为500,半秒钟)

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Collections;

namespace TimerTest

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void timer1_Tick(object sender, EventArgs e)

{

int intX = this.pictureBox1.Left;//控件左边缘与容器的距离

int intY = this.pictureBox1.Top;

int intWidth = this.pictureBox1.Width;

int intHeight = this.pictureBox1.Height;

intX += 10; //每次运动10px

if (intX>=this.Width)//运动超出可视范围内

{

intX =this.pictureBox1.Left-this.Width; //重新设置起点

}

this.pictureBox1.SetBounds(intX, intY, intWidth, intHeight);//绑定gif图片的坐标实现运动效果

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: