C#有两个form,form1和form2,form1上有button1和button2点击button1后form2出现点击button2后在form的
C#有两个form,form1和form2,form1上有button1和button2,点击button1后form2出现,点击button2后在form2的textbox1出现1234,应该怎么编写代码啊?我的form2出现在form1的指定panel1上,我的button1点击事件下的代码是
private void button1_Click(object sender, EventArgs e)
{
Form Form30 = new Form2();
Form30.TopLevel = false;
Form30.Parent = panel1;
Form30.Size = panel1.Size;
Form30.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
Form30.Show();
}
现在只是不知道button2点击之后 的代码应该怎么编写,求各位前辈指点,新学c#
------解决方案-------------------- Form2 fr2 = new Form2();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//string date = "2013-3-21";
//label1.Text = Convert.ToDateTime(date).ToLongDateString();
fr2.Show();
}
private void button2_Click(object sender, EventArgs e)
{
TextBox tb = (TextBox)fr2.Controls.Find("textBox1", true)[0];
tb.Text = "1234";
}
------解决方案--------------------
//Form2中假如如下代码
public string Form2Value
{
get
{
return this.textBox1.Text;
}
set
{
this.textBox1.Text = value;
}
}
//Form1调用
Form2 myForm = new Form2();
public Form1()
{
InitializeComponent();
}