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. Newbie: Stupid question about forms & variables...

Newbie: Stupid question about forms & variables...

Scheduled Pinned Locked Moved C#
question
6 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.
  • P Offline
    P Offline
    Phillip Hodges
    wrote on last edited by
    #1

    This is probably a very silly question. I am opening a form(b) from within another form(a) and I am trying to get a variable from form(a) and display its contents in form(b). But I don't know how? I will also be updating the variables in form(a) from form(b)? I have searched for ideas, but not sure what to search for? Thanks in advance, Phil

    "Rules are for the obedience of fools and the guidance of wise men"

    V G S C 4 Replies Last reply
    0
    • P Phillip Hodges

      This is probably a very silly question. I am opening a form(b) from within another form(a) and I am trying to get a variable from form(a) and display its contents in form(b). But I don't know how? I will also be updating the variables in form(a) from form(b)? I have searched for ideas, but not sure what to search for? Thanks in advance, Phil

      "Rules are for the obedience of fools and the guidance of wise men"

      V Offline
      V Offline
      V 0
      wrote on last edited by
      #2

      Create a public property in form B that sets the variable in form B from Form B to A is more tricky, or you'll need to pass the object A itself to B or you'll have to create your own event. thus in form A you'll have something like: MyForm B = new MyForm(); B.MyProperty = variablefromA; B.showDialog(); to pass the object A to form B you could pass it through the constructor (MyForm B = new MyForm(this);) I hope for you this isn't homework...?

      V. Stop smoking so you can: enjoy longer the money you save.

      1 Reply Last reply
      0
      • P Phillip Hodges

        This is probably a very silly question. I am opening a form(b) from within another form(a) and I am trying to get a variable from form(a) and display its contents in form(b). But I don't know how? I will also be updating the variables in form(a) from form(b)? I have searched for ideas, but not sure what to search for? Thanks in advance, Phil

        "Rules are for the obedience of fools and the guidance of wise men"

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        There are generally two methods used: 1. Send a reference to form A to the constructor of form B, and store the reference in form B. Then you can access form A using the reference. 2. Make the variables in form A static, then you can access them from anywhere by specifying the class name of the form. This of course limits you to never create more than one instance of the form.

        --- b { font-weight: normal; }

        1 Reply Last reply
        0
        • P Phillip Hodges

          This is probably a very silly question. I am opening a form(b) from within another form(a) and I am trying to get a variable from form(a) and display its contents in form(b). But I don't know how? I will also be updating the variables in form(a) from form(b)? I have searched for ideas, but not sure what to search for? Thanks in advance, Phil

          "Rules are for the obedience of fools and the guidance of wise men"

          S Offline
          S Offline
          Stefan Troschuetz
          wrote on last edited by
          #4

          Take a look at the following article[^].


          "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

          www.troschuetz.de

          C 1 Reply Last reply
          0
          • P Phillip Hodges

            This is probably a very silly question. I am opening a form(b) from within another form(a) and I am trying to get a variable from form(a) and display its contents in form(b). But I don't know how? I will also be updating the variables in form(a) from form(b)? I have searched for ideas, but not sure what to search for? Thanks in advance, Phil

            "Rules are for the obedience of fools and the guidance of wise men"

            C Offline
            C Offline
            Colin Angus Mackay
            wrote on last edited by
            #5

            See this article: Passing values between forms[^]


            Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

            1 Reply Last reply
            0
            • S Stefan Troschuetz

              Take a look at the following article[^].


              "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

              www.troschuetz.de

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              You beat me to it! :-D


              Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

              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