Help EventHandler in toolstrip User Control

  • Thread starter Thread starter lorenilla26
  • Start date Start date
L

lorenilla26

Guest
when opening a window from a form1 with the toolstrip button and then closing it from form2, the handler is returned to the button that opens it and I must close it twice ... any idea?

public partial class UC_ToolBar : UserControl
{


#region EventHandler
public delegate void BotonIngresarEventHandler(object sender, EventArgs e);
public event BotonIngresarEventHandler BotonIngresar;


public delegate void BotonSalirEventHandler(object sender, EventArgs e);
public event BotonSalirEventHandler BotonSalir;

#endregion
public UC_ToolBar()
{
InitializeComponent();

#region EventHandler Click
btnIngresar.Click += new EventHandler(BtnIngresar_Click);
btnSalir.Click += new EventHandler(BtnSalir_Click);
#endregion
}
private void BtnIngresar_Click(object sender, EventArgs e)
{
//// Delegar el evento al formulario que lo llama
if (BotonIngresar != null)
BotonIngresar(this, e);
}

private void BtnSalir_Click(object sender, EventArgs e)
{
if (BotonSalir != null)
BotonSalir?.Invoke(this, e);
}

}


public Form1()
{
InitializeComponent();
}

private void uC_ToolBar1_BotonIngresar(object sender, EventArgs e)
{
Form2 Ventana = new Form2();
Ventana.ShowDialog();
}




public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void uC_ToolBar1_BotonSalir(object sender, EventArgs e)
{
Close();
}

Continue reading...
 
Back
Top