Click here to Skip to main content
15,916,280 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to set value of a label in FORM_2 from the local variable ID from FORM_1?
Posted
Updated 1-May-13 19:52pm
v2

C#
public Int  kmp=0;
 private void Button_Click(object sender, EventArgs e)
        {
kmp=ur value;
           Form2 qu = new Form2 ();
            qu.ShowDialog();
}

C#
private void Form2_Load(object sender, EventArgs e)
        {
           Form1 l = new Form1();
          label1.text=  l.kmp.toString() ;
        }



Or
C#
private void Button_Click(object sender, EventArgs e)
        {

           Form2 qu = new Form2 (ur value);
            qu.ShowDialog();
}


C#
public Form2(int l)
       {
           InitializeComponent();
 label1.text=l.toString();
       }
 
Share this answer
 
v2
Comments
riodejenris14 2-May-13 3:14am    
Error : cannot implicitly convert type int to string
KM Perumal 2-May-13 3:16am    
make toString()
riodejenris14 2-May-13 3:42am    
i make it to string but the value it shows is zero only.
KM Perumal 2-May-13 3:44am    
Post ur code
riodejenris14 2-May-13 4:34am    
(Form 1)
public int UID = 0;
wsTestService.LOGIN_HANDLER(textBox1.Text, textBox2.Text, out Msg, out Suc, out Role, out ID);
UID = ID;

(Form 2)
public void Form2_Load(object sender, EventArgs e)
{
Form1 objfrm1 = new Form1();
label2.Text = objfrm1.UID.ToString();
}
Form1 button event
C#
   public string kmp="";
private void Button_Click(object sender, EventArgs e)
       {
          Form2 qu = new Form2 ();
           qu.ShowDialog();
            lable.text =kmp;
       }

Form2 button event
C#
private void Button_Click(object sender, EventArgs e)
       {
          Form1 l = new Form1();
           l.kmp = textbox.text;
       }
 
Share this answer
 
Comments
riodejenris14 2-May-13 2:50am    
hello perumal, I am having label1 in FORM2. I have to display the value ID(integer) local variable in FORM1 to the label1 in FORM2.
Create a property on Form 2

C#
public string LblText
   {

           set { lable.text = value ;}
   }


and set value to this property from Form1 (before show dialog)
 
Share this answer
 
Comments
riodejenris14 2-May-13 2:10am    
ya my ques is how to set the value of label in form 2 from the local variable ID from form 1?
Amol_B 2-May-13 2:21am    
do you want to set label value before form 2 is called or after?
riodejenris14 2-May-13 2:38am    
After form 2 is called i want to set value for the label(form 2) from the local variable ID(form 1). The data type is int.

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