using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
namespace WindowsApplication1
{
class Class1
{
private Panel l;
Label la;
public Class1(Panel a)
{
this.l = a;
}
delegate void DAdd();
public void add()
{ if (this.l.InvokeRequired)//-----同下
{
this.l.Invoke(new DAdd(add));//------------帮忙解释下这句什么意思
}
else
{
int x = 0, y = 25;
la = new Label();
Random rand = new Random();
int r = rand.Next(97, 123);
x = rand.Next(0, 100);
la.Text = ((char)r).ToString();
this.l.Controls.Add(la);
la.Location = new Point(x, y);
while (true)
{
la.Location = new Point(x, y);
y++;
Thread.Sleep(500);
} }
}
}
}
--------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Control.CheckForIllegalCrossThreadCalls = false;
}
private void Form1_Load(object sender, EventArgs e)
{
Class1 cc = new Class1(this.panel1);
new Thread(new ThreadStart(cc.add)).Start();
} private void panel1_Paint(object sender, PaintEventArgs e)
{ } private void timer1_Tick(object sender, EventArgs e)
{
} }
}
为什么一运行窗口程序就死机??错哪?不加while循环的时候就可以运行..
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
namespace WindowsApplication1
{
class Class1
{
private Panel l;
Label la;
public Class1(Panel a)
{
this.l = a;
}
delegate void DAdd();
public void add()
{ if (this.l.InvokeRequired)//-----同下
{
this.l.Invoke(new DAdd(add));//------------帮忙解释下这句什么意思
}
else
{
int x = 0, y = 25;
la = new Label();
Random rand = new Random();
int r = rand.Next(97, 123);
x = rand.Next(0, 100);
la.Text = ((char)r).ToString();
this.l.Controls.Add(la);
la.Location = new Point(x, y);
while (true)
{
la.Location = new Point(x, y);
y++;
Thread.Sleep(500);
} }
}
}
}
--------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Control.CheckForIllegalCrossThreadCalls = false;
}
private void Form1_Load(object sender, EventArgs e)
{
Class1 cc = new Class1(this.panel1);
new Thread(new ThreadStart(cc.add)).Start();
} private void panel1_Paint(object sender, PaintEventArgs e)
{ } private void timer1_Tick(object sender, EventArgs e)
{
} }
}
为什么一运行窗口程序就死机??错哪?不加while循环的时候就可以运行..
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货