方法一:【通过Form类构造方法的重载传参】
Form1类中代码:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2(textBox1.Text);
f2.ShowDialog();
}
}
Form2类中代码:
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public Form2(string str)
{
InitializeComponent();
textBox2.Text = str; //
}
}
效果图:
方法二、【通过Form类字段属性或公共静态类传递】