|
用Timer控件,合法死循环,参上!
两个Timer.
//首先定位窗体
//Form1_Lodo事件:
Point p=new Point(0,100);
this.DesktopLocation=p;
//设置timer1,timer2为10毫秒变一次
//timer1_Tick事件:
Point p=new Point(this.DesktopLocation.x+1,this.DesktopLocation.y);
this.DesktopLocation=p;
if(p.x==550) //如果达成条件就停止timer1执行timer2
{
timer1.Enabled=false;
timer2.Enabled=true;
}
//timer2_Tick事件:
Point p=new Point(this.DesktopLocation.x-1,this.DesktopLocation.y);
this.DesktopLocation=p;
if(p.x==-150) //如果达成条件就停止timer2执行timer1
{
timer1.Enabled=true;
timer2.Enabled=false;
}
//点击按纽停止飘动
//button1_Click:
tihs.timer1.Stop();
this.timer2.Stop();
完了,本以为可以看到飘动的窗体,可看见的是窗体在那里一动不动......:L |
|