Reputation: 21
I wrote a user control. I have a panel, when I click on the button in user control it is added to the panel. I have created a click event for user control. When clicked, the user control is removed from the panel. I want to ask that to catch the event when the user control is removed, which event should I use and use for panel or user control. For example, I add a label, when adding user control the label will change, and when deleting, the label will also change. Sorry for my bad English.
Upvotes: 0
Views: 397
Reputation: 16433
The event you are most likely to find helpful is the ControlRemoved
event of the Control
.
This is described in the docs thus:
Occurs when a control is removed from the Control.ControlCollection.
In the case of your example, you would add an event handler for this to the Panel
. Assuming your panel is named panel1
(please don't name it that) this would be something like this:
// In initialisation code somewhere
panel1.ControlRemoved += panel1_ControlRemoved;
private void panel1_ControlRemoved(object sender, ControlEventArgs e)
{
// Do something
...
// Note: removed control is referenced by e.Control
}
This would be raised anytime a control is removed from the Panel
.
There's also an accompanying event for when a control is added which is named ControlAdded
.
Upvotes: 0