Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm developing a windows application. In that application I'm using two forms. I need to get the text property of a texbox on the first form from the second form.

In web applications we use sessions. What can I use instead of sessions in a windows application?

Please give me some idea or a one sample solution.

Thanks
Posted
Updated 8-Oct-10 0:06am
v2

In window application you will have to pass the value to the Constructor of other page.

Simply assume

if you want to pass from Form1 to Form2
call Form2 like

Form2 form2 = new Form2(txtTest.Text);


put constructor at receiving side

Class Form2
{
Form2(string tempText)
{
txtTest.Text = tempText;
}
}


and your'e done.

Please vote and Accept Answer if it Helped.
 
Share this answer
 
v2
Comments
Johnny J. 8-Oct-10 5:58am    
He's asking about windows applications - not web applications, so there is no "redirected page".

Your technique will work for windows forms as well, but only if he opens Form2 from Form1. If both forms are open at the same time (from Form3) then he will need to take another approach.

@ ajay.rahu531: You need to supply us with more information; How are the forms opened? What relationship do they have with one another?
Hope it may satisfies your need.

Hiren's Answer is also an beautiful one.
For Assumption:
In Form1 Declare
public static string TextboxText;

If i Click on Button1 of Form1

i am going to Capture Textbox1.Text in TextboxText
ie
TextboxText= Textbox1.Text;

When i open Form2
Just assign TextboxText to Textbox2 in Form2
ie

Textbox2.Text=Form1.TextboxText;
 
Share this answer
 
v2
Comments
Pawan Kiran 8-Oct-10 7:07am    
Before u Vote for an answer, let me know the reason, it would helpful for me to gain better knowledge.
Simon_Whale 8-Oct-10 10:59am    
not really the best way to go around it.

use either overloading of the new subrountine of the destination form, if you are passing the information when loading the second form

or properties on the second form that you pass the information through but as another poster stated we need to know more information to help out the OP better
u can try this by usind object of the form..
like form1.show();
 
Share this answer
 
Comments
Simon_Whale 8-Oct-10 10:59am    
no your showing the form not passing the information with that instruction

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900