c# 一个窗口点击另外一个窗口触发事件

2024-12-22 13:15:00
推荐回答(1个)
回答1:

参考
form1上代码

private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Owner = this;
f2.ShowDialog();
}

public void test(string txt)
{
textBox1.Text = txt;

}

form2上代码
private void button1_Click(object sender, EventArgs e)
{
Form1 f1 = (Form1)this.Owner;
f1.test(textBox1.Text);
this.Close();
}