从一个窗体到另外一个窗体的委托没有问题。
然后从一个非窗体类 到 窗体 的委托时,出现错误。信息如下:
编写的程序代码如下
namespace thread_product_consume2
{
public delegate void UpdataTextBox(string str);
public class Sushi
{
public UpdataTextBox updata_TXT;
..............
}
class CellConsum { .....}
class CellProd{.....}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.textBox1.Text = null;
Add_Text("ABC1");
int result = 0;
Sushi FoodSushi = new Sushi();
FoodSushi.updata_TXT = new UpdataTextBox( Add_Text);
//用单元初始化二个实例
CellProd prod = new CellProd(FoodSushi, 20);
CellConsum consum = new CellConsum(FoodSushi, 20);
}
//在文本框输出文字
public void Add_Text(string str)
{
this.textBox1.Text +=str;
}
}