Answer the question
In order to leave comments, you need to log in
When displaying text from a TextBox from one form to a label of another form, the label disappears why?
I recently started learning C#.
Stupid problem, but when text is displayed from a TextBox from one form to the label of another form, the label disappears. why?
Here is the button code.
private void B_Ready_Click(object sender, EventArgs e)
{
Form_Registration f1 = new Form_Registration();
form2 f2 = new form2();
f2.Show();
f2.LB_name.Text = f1.TB_name.Text;
}
Answer the question
In order to leave comments, you need to log in
1) Not a good practice to give access to form controls from outside. It is better to define a public method that will change the text of the label, but access directly to the control will be closed inside the form (well, or here as a public property)
// this code is inside form2
public string LabelText
{
get
{
return this.LB_name.Text;
}
set
{
this.LB_name.Text = value;
}
}
private void B_Ready_Click(object sender, EventArgs e)
{
var f2 = new Form2();
f2.LabelText = "bla bla";
f2.Show();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question