//from1代码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 WindowsApplication4 { public partial class Form1 : Form { private Form2 frm= new Form2(); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Thread th1 = new Thread(new ThreadStart(show)); th1.Start();
Thread th = new Thread(new ThreadStart(start)); th.Start(); } private void Form1_Load(object sender, EventArgs e) { } private void start() { frm.SetLableText("开始"); Thread.Sleep(3000); frm.SetLableText("1"); Thread.Sleep(3000); frm.SetLableText("结束"); } private void show() { frm.ShowDialog(); } } //form2代码using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;namespace WindowsApplication4 { public partial class Form2 : Form { delegate void SetLableTextCallback(string str); public Form2() { InitializeComponent(); } public void SetLableText(string str) { if (label1.InvokeRequired) { SetLableTextCallback d = new SetLableTextCallback(SetLableText); this.Invoke(d, new object[] { str }); } else { label1.Text = str; } } private void Form2_Load(object sender, EventArgs e) { }
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;namespace WindowsApplication4
{
public partial class Form1 : Form
{
private Form2 frm= new Form2();
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Thread th1 = new Thread(new ThreadStart(show));
th1.Start();
Thread th = new Thread(new ThreadStart(start));
th.Start();
} private void Form1_Load(object sender, EventArgs e)
{ }
private void start()
{
frm.SetLableText("开始");
Thread.Sleep(3000);
frm.SetLableText("1");
Thread.Sleep(3000);
frm.SetLableText("结束");
}
private void show()
{
frm.ShowDialog();
}
}
//form2代码using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication4
{
public partial class Form2 : Form
{
delegate void SetLableTextCallback(string str);
public Form2()
{
InitializeComponent();
} public void SetLableText(string str)
{
if (label1.InvokeRequired)
{
SetLableTextCallback d = new SetLableTextCallback(SetLableText);
this.Invoke(d, new object[] { str });
}
else
{
label1.Text = str;
}
}
private void Form2_Load(object sender, EventArgs e)
{ }
}
}//from1窗体有一个buuton,form2有一个lable,在lable显示提示