找回密码
 入驻
搜索
查看: 44088|回复: 3

窗体飘动的问题(C#)

[复制链接]
发表于 2006-6-11 14:09:36 | 显示全部楼层 |阅读模式
用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
发表于 2006-6-11 15:00:11 | 显示全部楼层
是这样的
  1.       private System.Windows.Forms.Timer timer1;
  2.         private System.Drawing.Point P2 = new System.Drawing.Point(0, 0);

复制代码

  1.         private void Form1_Load(object sender, EventArgs e)  //LOAD事件,设置初始位置
  2.         {
  3.             Point P = new Point();
  4.             P.X = 0;
  5.             P.Y = 0;
  6.             this.DesktopLocation = P;
  7.         }

  8.         private void timer1_Tick(object sender, EventArgs e)  //X坐标和Y坐标+1
  9.         {
  10.             
  11.             P2.X += 1;
  12.             P2.Y += 1;
  13.             this.Location = new Point(P2.X,P2.Y);    //因为坐标的位置不是变量,所以要NEW一个出来
  14.      
  15.         }

复制代码


看明白了吗?~~~其他效果自己想想就可以弄出来了
回复

使用道具 举报

 楼主| 发表于 2006-6-11 19:13:15 | 显示全部楼层
Point P = new Point();
            P.X = 0;
            P.Y = 0;
            this.DesktopLocation = P;
一出来在左上角
Point p=new Point(0,100);
this.DesktopLocation=p;
一出来在左上角下来一点点
一样的吧
回复

使用道具 举报

发表于 2006-6-11 20:22:16 | 显示全部楼层
原帖由 zkkpkk 于 2006-6-11 19:13 发表
Point P = new Point();
            P.X = 0;
            P.Y = 0;
            this.DesktopLocation = P;
一出来在左上角
Point p=new Point(0,100);
this.DesktopLocation=p;
一出来在左上角下来一点 ...



一样的~~~这只是定义它的初始坐标而已!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 入驻

本版积分规则

QQ|Archiver|手机版|小黑屋|思明论坛

GMT+8, 2024-5-19 21:25 , Processed in 0.024479 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表