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. Windows Forms

Windows Forms

Scheduled Pinned Locked Moved C#
winformshelpquestion
11 Posts 6 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.
  • Q quiquex

    Need some help accesing methods of a parent form, from a child form. How is this done?

    D Offline
    D Offline
    DavidNohejl
    wrote on last edited by
    #2

    if those methods are public, child form can siply keep reference to it's parent.. oh wait.. that should we be in Owner property of child form, if you display it with ShowDialog( IWin32Window ) overload of that method. If they are not public, can you make them public? ( or internal) David

    1 Reply Last reply
    0
    • Q quiquex

      Need some help accesing methods of a parent form, from a child form. How is this done?

      M Offline
      M Offline
      Ming_Lei
      wrote on last edited by
      #3

      A parent form is a form which is a MdiContainer. A child form can call its parent using childfrom.MdiParent. ==== Lei Ming 2004 ===== ====================

      Q 1 Reply Last reply
      0
      • M Ming_Lei

        A parent form is a form which is a MdiContainer. A child form can call its parent using childfrom.MdiParent. ==== Lei Ming 2004 ===== ====================

        Q Offline
        Q Offline
        quiquex
        wrote on last edited by
        #4

        Yes but the methods of the parent form are not shown using childform.MdiParent What if i'm not using an MDI container?

        J 1 Reply Last reply
        0
        • Q quiquex

          Yes but the methods of the parent form are not shown using childform.MdiParent What if i'm not using an MDI container?

          J Offline
          J Offline
          Joshua Nussbaum
          wrote on last edited by
          #5

          You need to cast it the concrete class. i.e. MyMainForm frm = Parent as MyMainForm; 60% of statistics are made up on the spot

          Q 1 Reply Last reply
          0
          • J Joshua Nussbaum

            You need to cast it the concrete class. i.e. MyMainForm frm = Parent as MyMainForm; 60% of statistics are made up on the spot

            Q Offline
            Q Offline
            quiquex
            wrote on last edited by
            #6

            Still not getting it. This is my code: In the MainForm (GameForm)... BuyingForm f = new BuyingForm(new_item); //new instance of a "child" form GameForm gameForm = Parent as GameForm; f.Parent = gameForm; f.Show(); In the ChildForm (BuyingForm)... this.ParentForm.SomeMethod(); //the method is not listed

            D 1 Reply Last reply
            0
            • Q quiquex

              Still not getting it. This is my code: In the MainForm (GameForm)... BuyingForm f = new BuyingForm(new_item); //new instance of a "child" form GameForm gameForm = Parent as GameForm; f.Parent = gameForm; f.Show(); In the ChildForm (BuyingForm)... this.ParentForm.SomeMethod(); //the method is not listed

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #7

              Setup a field on your BuyingForm that holds a Form:

              public class BuyingForm : Form
              Form myParent;
              .
              .
              .
              myParent.PublicMethodCall( parameters );

              When you create an instance of this form, just set this field before you show the form:

              // GameForm code
              BuyingForm f = new BuyingForm(new_item);
              f.myParent = this;
              f.Show();

              If you use the Parent property of the form to do this, you could have some very strange and unintended side effects. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

              A 1 Reply Last reply
              0
              • D Dave Kreskowiak

                Setup a field on your BuyingForm that holds a Form:

                public class BuyingForm : Form
                Form myParent;
                .
                .
                .
                myParent.PublicMethodCall( parameters );

                When you create an instance of this form, just set this field before you show the form:

                // GameForm code
                BuyingForm f = new BuyingForm(new_item);
                f.myParent = this;
                f.Show();

                If you use the Parent property of the form to do this, you could have some very strange and unintended side effects. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                A Offline
                A Offline
                Anonymous
                wrote on last edited by
                #8

                What would be the safest way to do this? To avoid the strange unintended side effect.

                D 1 Reply Last reply
                0
                • A Anonymous

                  What would be the safest way to do this? To avoid the strange unintended side effect.

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #9

                  If you look at my previous post, you don't have to worry about it. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                  Q 2 Replies Last reply
                  0
                  • D Dave Kreskowiak

                    If you look at my previous post, you don't have to worry about it. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                    Q Offline
                    Q Offline
                    quiquex
                    wrote on last edited by
                    #10

                    Changed the code but i still cant access any user made methods in my parent form, and yes they are declared as public. All i can see is the usual methods, events and properties of a form. Sorry to be a drag but whats going on?

                    1 Reply Last reply
                    0
                    • D Dave Kreskowiak

                      If you look at my previous post, you don't have to worry about it. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                      Q Offline
                      Q Offline
                      quiquex
                      wrote on last edited by
                      #11

                      ok finally got it working, thanks for your help!

                      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