I have 2 forms, on the first one there are a lot of buttons (the name is not known beforehand), when I click on one of them, another button appears (Delete), after clicking on which a window is displayed confirming the action, where you need to select yes / no. If so, you need to remove the button on the first form. How to do this? I would be grateful for an example

  • btnToRemove.Parent.Controls.Remove(btnToRemove); - Igor
  • @Igor btnToRemove - here should be the name of the button to be deleted, right? only I don’t know the names of foreclosure - Vyacheslav
  • No, it should be a link to the control being deleted - Igor

1 answer 1

 private Control controlToRemove = null; private void button3_Click(object sender, EventArgs e) { // каким-то образом определяется, что нужно будет удалить. Например: controlToRemove = (Control)sender; } private void btnRemove_Click(object sender, EventArgs e) { if (controlToRemove != null) { if (/* показали второе окно и пользователь сказал "Да" */) { controlToRemove.Parent.Controls.Remove(controlToRemove); } } } 
  • A little bit wrong, but I completed it myself. Thank you for sending where necessary! - Vyacheslav