C#如何实现单击主窗口的一个按钮,然后弹出一个窗口,往这个子窗口的一个textbox里写东西,单击添加按钮就

急急急
2025-01-01 13:48:46
推荐回答(2个)
回答1:

弹出form2
private void button3_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();
frm.Owner = this;
frm.Show();
}
form2里单击添加按钮就写回到form1的textbox1里
private void button1_Click(object sender, EventArgs e)
{
Form1 frm1;
frm1 = (Form1)this.Owner;
frm1.textBox1.Text = textBox1.Text;
}

回答2:

public pritial class Form1:Form
{
public Form1()
{
InitCompoment();
}

public void button1_Click(object sender,EventArgs e)
{
Form2 fm = new Form2();
if (fm.DialogResult == DialogResult.OK)
{
this.label.Text = fm.tbText.Text;
}
}
}