passing variables from one form to another

G

Guest

Hello Everyone,

I am a web developer, but recently I have to work on a windows
application. In web page, we can pass the variables from one form to another
by querystring or session varaible and go to another web page by
Response.redirect("page2.aspx").

How can I go from one form to another form in windows application? Also, is
it possible to pass the values from one form to another form.

Thanks in advance.

-Vinki
 
G

Guest

Hi Vinki

You invoke a new form by creating new object of that form.
Form2 obj = new Form2(); // Constructor.
Form2.Show();

Option #1.
You can add a new overloaded Constructor in Form2 to accept required
parameters.
Form2 obj = new Form2(45,"Sort by OrderDate"); //Constructor.
Form2.Show();

Option #2.
Declare public properties in Form2 to pass values.
Form2 obj = new Form2(); //Constructor.
Form2.Property1 = value;
Form2.Property2 = value;
Form2.Show();

Regards
JIGNESH
 
S

SneeKeeFahk

Hello Vinki,

You could also use shared variables

on form2 decalre a friend shared variable
firend shared MyVar as string = ""

then from form1 you can access it like this
form2.MyVar = "MyString"

the down side to this is that all instances of form2 will share that
variable, so if your going to have more then 1 instance of form2 open at a
time use parameters that JIGNESH recommended

- SneeKee
 

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

Top