Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to access runtime methods of child form

How to access runtime methods of child form

Scheduled Pinned Locked Moved C#
helptutorialquestion
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vaibhavnvag
    wrote on last edited by
    #1

    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

    T 1 Reply Last reply
    0
    • V vaibhavnvag

      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

      T Offline
      T Offline
      Tyler45
      wrote on last edited by
      #2

      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!

      Q V 2 Replies Last reply
      0
      • T Tyler45

        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!

        Q Offline
        Q Offline
        quiteSmart
        wrote on last edited by
        #3

        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 :)

        T 1 Reply Last reply
        0
        • Q quiteSmart

          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 :)

          T Offline
          T Offline
          Tyler45
          wrote on last edited by
          #4

          ooppps :D but the result is same

          Q 1 Reply Last reply
          0
          • T Tyler45

            ooppps :D but the result is same

            Q Offline
            Q Offline
            quiteSmart
            wrote on last edited by
            #5

            yea sure it is the same. i just posted that for the thread poster to take attention to it. good job anyways:cool:

            1 Reply Last reply
            0
            • T Tyler45

              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!

              V Offline
              V Offline
              vaibhavnvag
              wrote on last edited by
              #6

              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

              C M 2 Replies Last reply
              0
              • V vaibhavnvag

                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

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • V vaibhavnvag

                  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

                  M Offline
                  M Offline
                  Martin 0
                  wrote on last edited by
                  #8

                  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

                  V 1 Reply Last reply
                  0
                  • M Martin 0

                    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

                    V Offline
                    V Offline
                    vaibhavnvag
                    wrote on last edited by
                    #9

                    Ok! Thank!!!! My problem is solved.....

                    Hallo

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups