I am developing a solution of type Windows Form that contains two forms:
Form frm_open_window :
Fields:
- (1) "Open" button: Opens the form called frm_new_window .
When this button is pressed, it should lock. Example:Abrir.Enabled = false;
Form frm_new_window :
Fields:
- (1) RadioButton: Determines if the frm_open_window form button is enabled.
- (1) Finish Button: Close the current form (frm_new_window) and should enable the form's button frm_open_window .
I was reviewing this question , but it doesn't apply to the situation I describe in my question.
The program flow is as follows:
- Press the button
Abrir
of the form frm_open_window . - The
OnClick
button's eventAbrir
opens an instance of the frm_new_window form and blocks the buttonAbrir
. - In the frm_new_window form , you can choose to select the
RadioButton
. - In the current form frm_new_window , press the button
Finalizar
, sending thechecked
(boolean) delRadioButton
to the first form i.e. frm_open_window . - Set the value of the attribute to the form's
Enabled
button frm_open_window .Abrir
Long story short, the problem I'm having right now is sending a boolean value between these two forms ; when the second form finishes its functionality, the button must be closed and enabled again Abrir
.
This is my current code:
Code of the frm_open_window form :
/// Propiedad pública del formulario "para habilitar el botón (Abrir)".
public bool EstadoBoton { get; set; }
/// <summary>
/// Abrir segundo formulario (frm_nueva_ventana).
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAbrir_Click(object sender, EventArgs e)
{
frm_nueva_ventana frmNewVnt = new frm_nueva_ventana();
frmNewVnt.Show();
btnAbrir.Enabled = false;
}
Code frm_new_window :
/// <summary>
/// Cerrar actual formulario (frm_nueva_ventana) y enviar
/// el checked del RadioButton al botón del primer formulario.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnFinalizar_Click(object sender, EventArgs e)
{
// frm_abrir_ventana aún está abierta y debe estarlo.
// por lo que no sé tampoco cómo detectar este proceso.
frm_abrir_ventana frmAbrVnt = new frm_abrir_ventana();
frmAbrVnt.Show();
frmAbrVtn.EstadoBoton = true;
}
How can I set this functionality correctly?
This may be a solution:
In the form frm_open_window
In the form frm_new_window
You don't have to create a new instance of
frm_abrir_ventana
when you want to go back to the parent window, you have to use the existing instancehere Communicate Forms
I explain on the subject
but basically you must have the instance of the parent form (in this case
frm_abrir_ventana
) from the form you are openingfrm_nueva_ventana
to know where you have to send the data from one window to the otherThe parent window sends its instance to the other form
The child window receives the instance and uses it to send the data
Observe how the instance is passed in the constructor of the form so as not to have to create a new one, thus being able to pass the value from one side to the other