hi everyone,

you know the same way you can set the label.text to have the same text as the one you fill in the textbox; mylabel.text=textbox1.text.
i realized that that happens only when both the label and the textbox are in the same form. is there a way that a label in another form can have data in filled in a textbox in a previous filled textbox.


elizabeth mwashuma

If you set the Modifiers property of the label on the second form to Public or Internal then you can directly set the lable text property just before showing the form.

Form tmpForm = new MyForm();
tmpForm.mylabel.Text = this.textbox1.Text;

Havn't you asked a similar question before?

Form2 fm2 = new Form2();
if (fm2.ShowDialog() == DialogResult.OK)
   mylabel.text = fm2.GetText();

and have a function in Form2

string GetText()
  return textbox1.text;

i don't understand.....i have a textbox in form1.cs and a label in form2.cs....all the codes provided above are giving errors....
i want text entered in textbox in form1.cs to be on a label in form2.cs
kindly assist.



in Form1

Form2 fm2 = new Form2(textbox1.text);
if (fm2.ShowDialog() == DialogResult.OK)
   //If ok then w/e

in Form2

string Fm1Text;

public Form2(string fm1Text)
   Fm1Text = fm1Text;


label1.text = Fm1Text
This question has already been answered. Start a new discussion instead.