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. Windows Forms
  4. Accessing parent form from child from

Accessing parent form from child from

Scheduled Pinned Locked Moved Windows Forms
question
5 Posts 2 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.
  • B Offline
    B Offline
    BDJones
    wrote on last edited by
    #1

    Please feel free to correct any terminoligy mistakes. From the main form 'frmMain' a child form 'frmChild' is instantiated and displayed. When 'frmChild' has focus and user is interacting, I need to cause a change on the parent form 'frmMain'. How do I get to cbOptionA (a checkbox) in frmMain? frmMain.cbOptionA.Checked = true; obviously wont work as that is the name of the class. Anyone care to school me? Thanks.

    D 1 Reply Last reply
    0
    • B BDJones

      Please feel free to correct any terminoligy mistakes. From the main form 'frmMain' a child form 'frmChild' is instantiated and displayed. When 'frmChild' has focus and user is interacting, I need to cause a change on the parent form 'frmMain'. How do I get to cbOptionA (a checkbox) in frmMain? frmMain.cbOptionA.Checked = true; obviously wont work as that is the name of the class. Anyone care to school me? Thanks.

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      You can do this by two ways: 1. If there is any event in the child form, due to which the check box in main form should get checked, use a delegate and handle it in the main form itself. Now within that event, you can check your checkbox. 2. Have a public static property for the checked property of your checkbox, say OptionAChecked in your main form. Now, from the child form you can access that property and set it to true. You can access the property from the child without worrying about the instance. ie if the name of your main form class is Mainform, you can use MainForm.OptionAChecked

      50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

      B 1 Reply Last reply
      0
      • D dan sh

        You can do this by two ways: 1. If there is any event in the child form, due to which the check box in main form should get checked, use a delegate and handle it in the main form itself. Now within that event, you can check your checkbox. 2. Have a public static property for the checked property of your checkbox, say OptionAChecked in your main form. Now, from the child form you can access that property and set it to true. You can access the property from the child without worrying about the instance. ie if the name of your main form class is Mainform, you can use MainForm.OptionAChecked

        50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

        B Offline
        B Offline
        BDJones
        wrote on last edited by
        #3

        Using suggestion 2, once the property has been changed by child in MainForm, how do I get MainForm to act upon that change? THank you

        D 1 Reply Last reply
        0
        • B BDJones

          Using suggestion 2, once the property has been changed by child in MainForm, how do I get MainForm to act upon that change? THank you

          D Offline
          D Offline
          dan sh
          wrote on last edited by
          #4

          If you have handled the CheckChanged event for the checkbox, it will fire when you change the checked state of your checkbox. If not, then you can handle it to get some work done.

          50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

          B 1 Reply Last reply
          0
          • D dan sh

            If you have handled the CheckChanged event for the checkbox, it will fire when you change the checked state of your checkbox. If not, then you can handle it to get some work done.

            50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

            B Offline
            B Offline
            BDJones
            wrote on last edited by
            #5

            I guess I'm not understanding how the property will update the checkox. The child is updating the property in frmMain. How does the checkbox in frmMain know the property just changed? Sorry if I'm missing something obvious.

            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