我有一个父窗体,其中有一个textbox1和一个panel1和一个button1。我在button1点击面板1中打开另一个窗体(比如form2)。 form2有一个文本框和按钮。当我在文本框中输入一个值并单击子窗体中的按钮时,子窗体的textboxvalue应该被复制到父窗体的文本框值,并且panel1应该变为不可见。父窗体中的子窗体如何访问父窗体控件的按钮单击
我用下面的代码, 为Button1点击(parentform的),
panel1.Visible = true;
Form2 f2 = new Form2();
f2.TopLevel = false;
f2.AutoScroll = true;
panel1.Location = new Point(this.ClientSize.Width/2 - panel1.Size.Width/2, this.ClientSize.Height/2 - panel1.Size.Height/2);
panel1.Anchor = AnchorStyles.None;
panel1.Controls.Add(sp);
f2.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
f2.Dock = DockStyle.Fill;
f2.usrnam = this.usrnam;
f2.connectionstring = this.connectionstring;
f2.Show();
对于子窗体的按钮点击,
string s = textBox1.Text;
Form1 f1= new Form1(); /* However this line is wrong , I donot want to initialize the form again i just need a way to access Form1 controls */
f1.panel1.Visible = false;
f1.textBox1.Text = s;
为什么在构造函数中没有通过Form1上的,然后保持一个本地副本它在形式2? – ZoomVirus 2015-03-02 12:53:48