How to access runtime methods of child form
-
I want to access child forms save method through mdi toolbar save button. how can i acesss that method runtime. because when i call active from's save method it gives me error method or member not define.
Hallo
-
I want to access child forms save method through mdi toolbar save button. how can i acesss that method runtime. because when i call active from's save method it gives me error method or member not define.
Hallo
-
you can do parent form's method as public and then on your chid form
frmParent frm = new frmParent(); frm.MypublicMethod();
i hope that it is ok for u!I think he wants to access a child's method from a parent. he should do the same as u said but with the child form :)
-
I think he wants to access a child's method from a parent. he should do the same as u said but with the child form :)
-
yea sure it is the same. i just posted that for the thread poster to take attention to it. good job anyways:cool:
-
you can do parent form's method as public and then on your chid form
frmParent frm = new frmParent(); frm.MypublicMethod();
i hope that it is ok for u!Hi, Its Ok!But i want to decide at runtime which child forms method will run. Suppose Form1 is mdi and Form2/from3.... is child; Form2/form3..... contains save() mehod; i want active forms save() method like Form f=new Form2(); ///Form2 is Currently Active.. f.save(); like
Hallo
-
Hi, Its Ok!But i want to decide at runtime which child forms method will run. Suppose Form1 is mdi and Form2/from3.... is child; Form2/form3..... contains save() mehod; i want active forms save() method like Form f=new Form2(); ///Form2 is Currently Active.. f.save(); like
Hallo
vaibhavnvag wrote:
Form f=new Form2(); ///Form2 is Currently Active..
Unless Form is not the base Form class, but one that you defined to use polymorphically, the problem here is that although f is a Form2, you only *know* it's a Form. You need to use reflection, or cast the variable to the right type, before you can see methods that are only on the derived class.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
Hi, Its Ok!But i want to decide at runtime which child forms method will run. Suppose Form1 is mdi and Form2/from3.... is child; Form2/form3..... contains save() mehod; i want active forms save() method like Form f=new Form2(); ///Form2 is Currently Active.. f.save(); like
Hallo
Hello, First you should build a base Form (BasicForm) from where your Form2 and Form3 inherit. If save() method in Form2 and Form3 are different: This BasicForm has than a virtual method save() which is overriden in Form2 and Form3. If its the same functionality in both forms, you just have to make the method once in BasicForm. Then in Form1 code you could do:
BasicForm activeForm= this.ActiveMdiChild as BasicForm;
if(activeForm!=null)
{
activeForm.save();
}Hope that helps! All the best, Martin
-
Hello, First you should build a base Form (BasicForm) from where your Form2 and Form3 inherit. If save() method in Form2 and Form3 are different: This BasicForm has than a virtual method save() which is overriden in Form2 and Form3. If its the same functionality in both forms, you just have to make the method once in BasicForm. Then in Form1 code you could do:
BasicForm activeForm= this.ActiveMdiChild as BasicForm;
if(activeForm!=null)
{
activeForm.save();
}Hope that helps! All the best, Martin
Ok! Thank!!!! My problem is solved.....
Hallo