This is suddenly used in today's work, but I have never touched it before! However, with the help of experienced colleagues, the problem was quickly solved. You can use the following methods:
1. When a child form object is constructed in the parent form, the parent form is passed over:
For example, FrmSub frm = new FrmSub (this); // this indicates the parent form
2. Change the variables and methods to be accessed in the parent form to public.
3. Define the global variable of a parent form in the child form class:
For example, private dynamic m_parentContainer; // you can use dynamic to dynamically identify the type of the variable.
4. Add reference Microsoft. CSharp. dll
5. directly use m_parentContainer. variable name or m_parentContainer. method name for access.
If (m_ParentContainer.mFrm2BaseLibDataEdite = null | m_ParentContainer.mFrm2BaseLibDataEdite.IsDisposed) // mFrm2BaseLibDataEdite is the parent form variable
{
M_ParentContainer.mFrm2BaseLibDataEdite = new frm2BaseLibDataEdite ();
If (m_ParentContainer.mFrm2BaseLibDataEdite.IsDisposed = false)
{
M_ParentContainer.fnAddChildFormToMDIForm (m_ParentContainer.mFrm2BaseLibDataEdite); // fnAddChildFormToMDIForm () is the parent form Method
M_ParentContainer.mFrm2BaseLibDataEdite.Show ();
}
}
Else {
M_ParentContainer.mFrm2BaseLibDataEdite.WindowState = FormWindowState. Maximized;
M_ParentContainer.mFrm2BaseLibDataEdite.Activate ();
M_ParentContainer.mFrm2BaseLibDataEdite.Show ();
}