How can I pull the label from form1 to form2 to give label.Refresh?
How can I pull the label from form1 to form2 to give label.Refresh?
When you instantiate form 2 when constructing it, you need to pass a reference to the object of form 1 (Previous Form), that is, to have a property of type Form1. So that in form 2 you call a public method that updates, or directly access the property of the object if it is public. Studying object orientation helps you to better understand.
Example of what the two Forms class looks like: Form 1
public partial class Form1 : Form
{
public label labelNome;
public void AbrirForm2()
{
Form2 segundoForm = new Form2();
segundoForm.form1Reference = this;
}
}
Form 2
public partial class Form2 : Form
{
public Form1 form1Reference = null;
public void EventoQueAlteraLabelDoForm1()
{
if(form1Reference != null)
form1Reference.labelNome.text = "Hello World";
}
}