I need to click on a button, "select" that button, and by clicking on an erase button, that control will be deleted. How could I do that ?.
I need to click on a button, "select" that button, and by clicking on an erase button, that control will be deleted. How could I do that ?.
public partial class Form1 : Form
{
Button mLastSelection;
public Form1()
{
InitializeComponent();
for (int i = 0; i < 5; i++)
{
Button btn = new Button();
btn.Text = "Seleccione" + i;
btn.Location = new Point(0, btn.Height * i);
btn.Click += new EventHandler((sender, args) =>
{
mLastSelection = sender as Button;
});
this.Controls.Add(btn);
}
Button borrarSeleccion = new Button();
borrarSeleccion.Location = new Point(borrarSeleccion.Width + 15, 0);
borrarSeleccion.Text = "Borrar Seleccionado";
borrarSeleccion.Click += new EventHandler((sender, args) =>
{
mLastSelection?.Dispose();
});
this.Controls.Add(borrarSeleccion);
}
}