各位大侠帮我看看下面的代码,我写的一个画圆点程序,在写while循环时出现错误了,当我运行时一点击窗口,它就说“程序未响应”要强行关闭,谢谢各位!
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace waTenCharacter
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnStart;
private System.Windows.Forms.Button btnStop;
private System.Windows.Forms.Button btnClose;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
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()
{
this.btnStart = new System.Windows.Forms.Button();
this.btnStop = new System.Windows.Forms.Button();
this.btnClose = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnStart
//
this.btnStart.Location = new System.Drawing.Point(192, 48);
this.btnStart.Name = "btnStart";
this.btnStart.TabIndex = 0;
this.btnStart.Text = "Start";
this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
//
// btnStop
//
this.btnStop.Location = new System.Drawing.Point(192, 96);
this.btnStop.Name = "btnStop";
this.btnStop.TabIndex = 1;
this.btnStop.Text = "Stop";
this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
//
// btnClose
//
this.btnClose.Location = new System.Drawing.Point(192, 144);
this.btnClose.Name = "btnClose";
this.btnClose.TabIndex = 0;
this.btnClose.Text = "Close";
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.btnClose);
this.Controls.Add(this.btnStop);
this.Controls.Add(this.btnStart);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void btnStart_Click(object sender, System.EventArgs e)
{
int width = 10;
int high = 10;
int n = 1;
Graphics g = this.CreateGraphics();
System.Drawing.Drawing2D.LinearGradientBrush myBrush = new System.Drawing.Drawing2D.LinearGradientBrush(ClientRectangle,Color.Gray, Color.Gray, System.Drawing.Drawing2D.LinearGradientMode.Vertical);
System.Drawing.Drawing2D.LinearGradientBrush myBrush1 = new System.Drawing.Drawing2D.LinearGradientBrush(ClientRectangle,Color.Green, Color.Green, System.Drawing.Drawing2D.LinearGradientMode.Vertical);
System.Drawing.Drawing2D.LinearGradientBrush myBrush2 = new System.Drawing.Drawing2D.LinearGradientBrush(ClientRectangle,Color.Red, Color.Red, System.Drawing.Drawing2D.LinearGradientMode.Vertical);
//g.FillRectangle(myBrush,x,y,width,high);
while(n<n+1)
{
n++;
for(int y = 0;y<100;y=y+10)
{
for(int x = 0; x<100;x= x+10)
{
g.FillEllipse(myBrush,x,y,width,high);
if(x == 50)
{
g.FillEllipse(myBrush1,50,y,width,high);
//System.Threading.Thread.Sleep(10);
}
else if(x == 40)
{
g.FillEllipse(myBrush1,40,y,width,high);
}
else if(y == 50)
{
g.FillEllipse(myBrush1,x,50,width,high);
}
else if(y == 40)
{
g.FillEllipse(myBrush1,x,40,width,high);
}
//System.Threading.Thread.Sleep(10);
}
}
System.Threading.Thread.Sleep(1000);
for(int y = 0;y<100;y=y+10)
{
for(int x = 0; x<100;x= x+10)
{
g.FillEllipse(myBrush,x,y,width,high);
if(x == 50)
{
g.FillEllipse(myBrush2,50,y,width,high);
//System.Threading.Thread.Sleep(10);
}
else if(x == 40)
{
g.FillEllipse(myBrush2,40,y,width,high);
}
else if(y == 50)
{
g.FillEllipse(myBrush2,x,50,width,high);
}
else if(y == 40)
{
g.FillEllipse(myBrush2,x,40,width,high);
}
//System.Threading.Thread.Sleep(10);
}
}
System.Threading.Thread.Sleep(1000);
//continue;
}
}
private void btnStop_Click(object sender, System.EventArgs e)
{
}
private void btnClose_Click(object sender, System.EventArgs e)
{
Close();
}
}
}