value in the variable expires

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

Guest

I have 2 forms. in form1 i declared a public variable in which a value is
stored. then i goto form2 . (for this is create an object of form2 in form1.)
when i go to form2 there is call form1. when i come to form1 the value stored
in the variable decalred in form1 gets lost. how can i retain those values?
 
Vijay said:
I have 2 forms. in form1 i declared a public variable in which a value is
stored. then i goto form2 . (for this is create an object of form2 in
form1.)
when i go to form2 there is call form1. when i come to form1 the value
stored
in the variable decalred in form1 gets lost. how can i retain those
values?

First forms are just classes like most things in .Net. It would seem that
you need to pass a reference of form1 to form2 so that from form 2 you can
access the public variable.

public class Form2 : Form
{
public Form2(Form1 form1)
{
form1.YourPublicVariable ....
}
}

SP
 
should i pass them to the next form and get them again to the first form in
order to reatin them.?
 
Vijay said:
should i pass them to the next form and get them again to the first form
in
order to reatin them.?

First ask yourself if the public variable on Form1 really belongs to Form1.
Perhaps you should be passing a class that holds this variable to each of
your forms. What is this public variable? Is Form1 the main form of your
application so it will always be instansiated?

SP
 

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