C# winForm subform accesses the controls of the parent form

Form part:
Form1: Main form (IsMdiContainer property is set to true, Modifiers property of textBox1 is set to public)
Form2: Subform
 
Code part:
//parent form
  Form2 f2 = new Form2();
  f2.Owner = this;
    f2.ShowDialog();
// Child body
     Form1 f1=new Form1();
     f1=(Form1)this.Owner;
     f1.textBox1.Text="Subform accesses main form";

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324809187&siteId=291194637