c#多窗口页面传值
winform多页面传值有很多方法,公有变量赋值,事件委托传值等很多。
演示下委托事件传值的方法
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 fm2 = new Form2();
fm2.c += new Form2.showshijian(niude);
fm2.ShowDialog();
}
public void niude()
{
this.textBox1.Text = "对了吗";
}
}
```csharp
在这里插入代码片
```csharp
public partial class Form2 : Form
{
public delegate void showshijian();
public event showshijian c;
public Form2()
{
InitializeComponent();
}
public void button1_Click(object sender, EventArgs e)
{
if (c != null)
{
c();
}
}
}