这几天闲着没有事,想编写一个模仿QQ显示与隐藏的程序,现在有问题如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace 仿真QQ
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private int x,y;
private System.ComponentModel.IContainer components;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(40, 144);
this.label1.Name = "label1";
this.label1.TabIndex = 0;
this.label1.Text = "label1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(172, 471);
this.Controls.Add(this.label1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "QQ";
this.Move += new System.EventHandler(this.Form1_Move);
this.MouseEnter += new System.EventHandler(this.Form1_MouseEnter);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Move(object sender, System.EventArgs e)
{
x = this.Left;
y = this.Top;
this.label1.Text=y.ToString();
while(y<=2&&y>=-480)
{
if(y==2)
{
MessageBox.Show("进入隐藏循环!");
Point p=new Point(x,y);
Point p1=new Point(p.X,p.Y);
this.DesktopLocation=p1;
y--;
}
else
{
Point p=new Point(x,y);
Point p1=new Point(p.X,p.Y);
this.DesktopLocation=p1;
y--;
}
}
}
private void Form1_MouseEnter(object sender, System.EventArgs e)
{
// MessageBox.Show("鼠标进入可见区域!"); //该句注释取消可以运行到
while(y>=-480&&y<=2)
{
if(y==-480)
{
MessageBox.Show("进入显示循环!");
Point p=new Point(x,y);
Point p1=new Point(p.X,p.Y);
this.DesktopLocation=p1;
y++;
}
else
{
Point p=new Point(x,y);
Point p1=new Point(p.X,p.Y);
this.DesktopLocation=p1;
y++;
}
}
}
}
}
上面红色部分代码为什么运行不到啊?