how to access a variables

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi i want to access a variables from form1 to form2
how should i declare on form1
and how can i get those values on form2
 
* "=?Utf-8?B?cnQ=?= said:
hi i want to access a variables from form1 to form2
how should i declare on form1
and how can i get those values on form2

You will have to pass a reference to your 'Form1' to 'Form2'. If you
are instantiating 'Form1' inside 'Form2', you could add a property of
type 'Form1' to your 'Form2' and set this property to your instance of
'Form2'.
 
Hi,

You can do the same as under:
In the form2, create an object of Form1 class.

Form1 f = new Form1();
MessageBox.Show(f.Property);

Alternately, the method suggested by Herfried is a better way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top