1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Data;5 usingSystem.Drawing;6 usingSystem.Linq;7 usingSystem.Text;8 usingSystem.Threading.Tasks;9 usingSystem.Windows.Forms;Ten One namespaceWindowsFormsApplication1 A { - Public Partial classForm1:form - { the Private stringname; - PublicForm1 () - { - InitializeComponent (); + } - + Private voidButton1_Click (Objectsender, EventArgs e) A { atForm2 Frm2 =NewForm2 (); -Frm2. MdiParent = This; - Frm2. Show (); - } - - Private voidButton2_Click (Objectsender, EventArgs e) in { -FORM3 Frm1 =NewForm3 (); toFrm1. MdiParent = This; + Frm1. Show (); - } the Public Eventaction<string>Ontext; * Public voidTochangetext (stringobj) $ {Panax Notoginseng if(Ontext! =NULL) - { the ontext (obj);} + } A Private voidForm1_Load (Objectsender, EventArgs e) the { + - } $ } $}
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Data;5 usingSystem.Drawing;6 usingSystem.Linq;7 usingSystem.Text;8 usingSystem.Threading.Tasks;9 usingSystem.Windows.Forms;Ten One namespaceWindowsFormsApplication1 A { - Public Partial classForm2:form - { the PublicForm2 () - { - InitializeComponent (); - } + - Private voidButton1_Click (Objectsender, EventArgs e) + { A( This. ParentForm asFORM1). Tochangetext ("Form2 the news? "); at } - } -}
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Data;5 usingSystem.Drawing;6 usingSystem.Linq;7 usingSystem.Text;8 usingSystem.Threading.Tasks;9 usingSystem.Windows.Forms;Ten One namespaceWindowsFormsApplication1 A { - Public Partial classForm3:form - { the PublicForm3 () - { - InitializeComponent (); - } + - Private voidForm3_load (Objectsender, EventArgs e) + { AMessageBox.Show ( This. Parentform.name); at( This. ParentForm asFORM1). Ontext + =Newaction<string>(form3_ontext); - } - Private voidForm3_formclosed (Objectsender, Formclosedeventargs e) - { -( This. ParentForm asFORM1). Ontext-=Newaction<string>(form3_ontext); - } in voidForm3_ontext (stringobj) - { toTextBox1.Text = textbox1.text+obj; + } - } the}
C # MDI child forms interoperate with each other