The parent form content that needs to be obtained in the subform method as
Checkformisopen
PrivateFrmmenu Frmmenu =NewFrmmenu (); PublicFrmmain () {InitializeComponent (); } Private voidFrmmain_load (Objectsender, EventArgs e) {FRMMENU.P_FM= This; Frmmenu.show ( This. Dockpanelmain); } Public BOOLCheckformisopen (stringformname) { BOOLRemark =false; for(intA =0; A <Base. Mdichildren.length; a++) { if(FormName. Equals (Base. Mdichildren[a]. GetType (). Namespace +"."+Base. Mdichildren[a]. GetType (). Name)) {Base. Mdichildren[a]. Activate (); Remark=true; } } returnremark; }
Subform:
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingWeifenLuo.WinFormsUI.Docking;namespacee24tt{ Public Partial classfrmmenu:dockcontent { PublicFrmmenu () {InitializeComponent (); } //formsub: Privatefrmmain FM; Publicfrmmain p_fm {Get{returnFM;} Set{fm =value;} } Private voidFrmmenu_load (Objectsender, EventArgs e) {Trvmenu.expandall (); } Private voidTrvmenu_afterselect (Objectsender, TreeViewEventArgs e) { Try { //formsub://when it is necessary to refresh its caller (parent) if( This. trvMenu.SelectedNode.Text! =NULL) { if( This. trvMenu.SelectedNode.Tag! =NULL) { stringFormName = This. trvMenu.SelectedNode.Tag.ToString (); if(!FM. Checkformisopen (FormName)) {FM. Openchildform (FormName); }}} FM. Text="the 24TT setting"+ This. TrvMenu.SelectedNode.Text; } Catch { } } }}
This method solves the problem of parent-child form passing value
Attribute method
Formfather:
Need to have a public refresh method
public void Refresh_method ()
{
//...
}
When called
Formsub F2 = new Formsub ();
F2. P_F1 = this; Emphasis, assigning values to the subform corresponding property
F2. Show ();
Formsub:
Private Formfather p_f1;
Public Formfather p_f1
{
Get{return p_f1;}
SET{P_F1 = value;}
}
When refreshed
P_f1. Refresh_method ();
C # WeifenLuo.WinFormsUI.Docking.dll application problem subset form Access parent form method