How to return a value from one form to another

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JnrJnr
    New Member
    • Oct 2009
    • 88

    #1

    How to return a value from one form to another

    How do I return (or pass) a simple value of a variable from one windows form to another?

    thanks!
  • maddyromeo
    New Member
    • Jul 2010
    • 22

    #2
    suppose that u have two forms Form1 and Form2.......
    and two variables 'a' and 'b' where 'a' belongs to Form1 and 'b' belongs to Form2... now if you want to pass value of 'a' to 'b' ........

    1) write a constructor in Form2 like

    public Form2(int value)
    {
    b = value;
    }

    2) Now instansiate the Form2 in Form1 by passing the value of "a" to the constructor like

    Form2 f2 = new Form2(a); //in Form1

    now you will have the value of 'a' as 'b' in Form2

    Comment

    • JnrJnr
      New Member
      • Oct 2009
      • 88

      #3
      Originally posted by maddyromeo
      suppose that u have two forms Form1 and Form2.......
      and two variables 'a' and 'b' where 'a' belongs to Form1 and 'b' belongs to Form2... now if you want to pass value of 'a' to 'b' ........

      1) write a constructor in Form2 like

      public Form2(int value)
      {
      b = value;
      }

      2) Now instansiate the Form2 in Form1 by passing the value of "a" to the constructor like

      Form2 f2 = new Form2(a); //in Form1

      now you will have the value of 'a' as 'b' in Form2
      Thank you maddyromeo!

      Comment

      Working...