今天在公司做关于gis地图的事,做的头疼,一点都不想做了,然后研究了下Winform中的Timer控件,可以用这个控件让窗体左右浮动。
分享下代码:用了两个timer控件,和一个Label控件。
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 WindowsFormsApplication2
{
public partial class Form3 : Form
{
private int t;
public Form3()
{
InitializeComponent();
Point p = new Point(0,240);
this.DesktopLocation = p;
this.timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
Point p = new Point(this.DesktopLocation.X+1,this.DesktopLocation.Y);
this.DesktopLocation = p;
if(p.X==550)
{
this.timer1.Stop();
MessageBox.Show("跑的好累啊","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
this.timer2.Start();
}
}
private void timer2_Tick(object sender, EventArgs e)
{
Point p = new Point(this.DesktopLocation.X-1,this.DesktopLocation.Y);
this.DesktopLocation = p;
if (p.X == 0)
{
t++;
this.timer2.Stop();
this.label1.Text = "劳资跑了"+t.ToString()+"圈了";
MessageBox.Show("加油,继续跑哦!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
this.timer1.Start();
}
}
}
}
本文分享了如何在Winform中利用Timer控件实现窗体的左右浮动效果,通过代码实例展示了使用两个Timer控件和一个Label控件的实现方式。
223

被折叠的 条评论
为什么被折叠?



