lundi 2 mars 2015

How can a subform inside a panel of parentform access parent form controls on button click

I have a parent form which has a textbox1 and a panel1 and a button1. I open another form(say form2) in panel1 on button1 click. form2 has a textbox and button. when i enter a value in textbox and click on the button in subform , the textboxvalue of subform should be copied to textbox value of parent form and panel1 should become invisible.


I use the following code, For button1 click(of 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();


For button click of subform,



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;

Aucun commentaire:

Enregistrer un commentaire