Click here to Skip to main content
15,899,474 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
how to get value in a text box to a label in another form?
Posted

C#
private void Button_Click(object sender, EventArgs e)
        {
 
           Form2 qu = new Form2 (textbox1.text);
            qu.ShowDialog();
}


C#
public Form2(string l)
       {
           InitializeComponent();
 label1.text=l.toString();
       }
 
Share this answer
 
Comments
geo thomas 8-May-13 2:59am    
thank u very much..
its work...thanks again..:-)
KM Perumal 8-May-13 3:00am    
welcome Accept answer its useful for another
geo thomas 8-May-13 3:06am    
k.
achalake 21-Jul-20 5:28am    
i recently started coding and i encountered the same problem. cud this solution be explained a bit more?
This is the popular question about form collaboration. The most robust solution is implementation of an appropriate interface in form class and passing the interface reference instead of reference to a "whole instance" of a Form. Please see my past solution for more detail: How to copy all the items between listboxes in two forms[^].

Please also see other solutions in this discussion. If the application is simple enough, the solution could be as simple as declaring of some internal property in one form and passing a reference to the instance of one form to the instance of another form. For more complex projects, such violation of strictly encapsulated style and loose coupling could add up the the accidental complexity of the code and invite mistakes, so the well-encapsulated solution would be preferable.

Please see also:
http://en.wikipedia.org/wiki/Accidental_complexity[^],
http://en.wikipedia.org/wiki/Loose_coupling[^].

—SA
 
Share this answer
 
C#
formname f=new formname();
label.text=f.textbox.text;
 
Share this answer
 
Comments
geo thomas 8-May-13 2:35am    
srry..is not working?am getting error
Error 5 'Employee_Login.Form1.txt_EId' is inaccessible due to its protection level

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