I have a windowsform application with 2 form and form2 windows, which is generated by default (I consider it the main one) and a 2nd form, and I wanted to access a textbox of the main form from it form2 form to update it with a button from this.
I found this solution that met the requirements:
Form created by default:
private void btnIngresar_Click(object sender, EventArgs e)
{
lavhs instancia = new lavhs();
usuario = txtboxUsuario.Text;
contra = txtboxContra.Text;
instancia.Show(this); // que envia? una instancia del form actual?
}
Form 2:
private void btnActualizar_Click(object sender, EventArgs e)
{
Form1.usuario = txtActualizar.Text; //envio el string a un string statico perteneciente al form principal
Form form1 = this.Owner; //Obtenemos el dueño del Form (no entiendo)
TextBox cajaTextoForm1 = (TextBox)form1.Controls["txtboxUsuario"]; //Obtenemos la caja de texto en Form1 (no entiendo)
//Le pasamos el texto introducido
cajaTextoForm1.Text = txtActualizar.Text;
}
My question is: How do you get access to the main form created by default, since I understand when creating an instance of the class, a different form is generated and this is not the case if you want to modify a controller an existing form that is already running, or I'm wrong in how I understand things.