1、常用属性
Interval 用于获取或设置Timer组件Tick事件发生的时间间隔,属性值不能小于1
制作左右飘摇窗体
private void timer1_Tick(object sender, EventArgs e)
{
Rectangle rect = Screen.GetWorkingArea(this);//获取屏幕大小
if (this.Left != (rect.Width - this.Width))
{
this.Left++;//窗体向右移动
this.Top += ;//窗体向下移动
}
else
{
timer1.Enabled = false;//停用Timer组件
timer2.Enabled = true;//启用Timer组件
}
}
private void timer2_Tick(object sender, EventArgs e)
{
Rectangle rect = Screen.GetWorkingArea(this);//获取屏幕大小
if (this.Left == )
{
timer2.Enabled = false;//停用Timer组件
timer1.Enabled = true;//启用Timer组件
}
else
{
this.Left--;//窗体向左移动
this.Top -= ;//窗体向上移动
}
}
倒计时
//变量用于存储年、月、日、时、分、秒
public long LogYear, logMonth, logDay, logHour, logMinte, logSencon;
private void timer1_Tick(object sender, EventArgs e)
{
DateTime get_time1 = DateTime.Now;//得到当前系统时间
DateTime sta_ontime1 = Convert.ToDateTime(//得到世界杯开幕时间
Convert.ToDateTime("2014-10-13 00:00:00"));
txtYear.Text = DateAndTime.DateDiff(//计算相隔年数
"yyyy", get_time1, sta_ontime1,
FirstDayOfWeek.Sunday,
FirstWeekOfYear.FirstFourDays).ToString();
txtMonth.Text = DateAndTime.DateDiff(//计算相隔月数
"m", get_time1, sta_ontime1,
FirstDayOfWeek.Sunday,
FirstWeekOfYear.FirstFourDays).ToString();
textday.Text = DateAndTime.DateDiff(//计算相隔天数
"d", get_time1, sta_ontime1,
FirstDayOfWeek.Sunday,
FirstWeekOfYear.FirstFourDays).ToString();
txtHour.Text = DateAndTime.DateDiff(//计算相隔小时数
"h", get_time1, sta_ontime1,
FirstDayOfWeek.Sunday,
FirstWeekOfYear.FirstFourDays).ToString();
txtmintue.Text = DateAndTime.DateDiff(//计算相隔分钟数
"n", get_time1, sta_ontime1,
FirstDayOfWeek.Sunday,
FirstWeekOfYear.FirstFourDays).ToString();
txtsecon.Text = DateAndTime.DateDiff(//计算相隔秒数
"s", get_time1, sta_ontime1,
FirstDayOfWeek.Sunday,
FirstWeekOfYear.FirstFourDays).ToString();
textBox1.Text = DateTime.Now.ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
textBox2.Text = //显示世界杯时间
"2014-10-13 00:00:00" + " 星期五";
timer1.Enabled = true;//开启计时器
}
制作动画
private void tmr_Action_Tick(object sender, EventArgs e)
{
CreateGraphics().DrawImage(//在窗体中绘制图片信息
Image.FromFile(
(index++ > ? (index = ) : index).
ToString() + ".jpg"), new Point(, ));
}