Click here to Skip to main content
15,910,009 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hai,

I am working in windows application.

My question is: I have 5 forms. In first form i entered some value in the textbox. I want to get this textbox value in my 5th form using c#. how to acheive it?
Posted

In case of Windows application, Either you can use Properties or Use parameterised constructor to do the same.

Using Parameterised Constructor
---------------------
Write the following code on button click event of Form1
C#
Form5 f=new Form5(textBox1.Text);
f.Show();

Get the value in the Form5 as
string sValue;
public Form5(string s)
{
   sValue=s;
}

Using Properties
-------------------
Define the property in Form2 as
C#
private string sValue;
public string Value
{
    get{return value;}
    set{value=sValue;}
}

and use the value of the variable as well.

Setting the value of textBox1 in Form1 as:
C#
Form2 f=new Form2();
f.Value=textBox1.Text;
 
Share this answer
 
v2
Comments
LanFanNinja 23-Nov-11 1:15am    
+5Member 7684075420 also see my solution(solution 2) in the link below if you need access to your first form.
http://www.codeproject.com/Answers/278345/Need-data-back-in-form1-Textbox1-while-coming-back#answer2
No. I think we can not use session in windows application. I want get first form textbox value in my fifth form. how to do?

Thanks
 
Share this answer
 

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