mzurita
mzurita

Reputation: 690

Catching event when a control loses child control

Imagine this application in Vb.net, I have 2 panels and several buttons. I am moving buttons from a panel to other panel (through catching drag and drop events). I reached it.

Now I am trying the following: Is there any way to raise an event from a panel when this panel loses some child button (or control)?

Thanks in advance.

Upvotes: 0

Views: 83

Answers (2)

Ibra
Ibra

Reputation: 190

Try this event when a control has added to the panel :

Private Sub Panel1_ControlAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles Panel1.ControlAdded

End Sub

And this when a control has removed :

Private Sub Panel1_ControlRemoved(ByVal sender As Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles Panel1.ControlRemoved

End Sub

Upvotes: 2

5uperdan
5uperdan

Reputation: 1501

The panel control doesn't seem to have an event that fires when its child control collection changes. source

The best thing to do would be handle this as part of the drop event. Presumably you have some code to determine if the button is to be moved. If this is true, call a function to do everything you want when a panel loses a control.

Upvotes: 1

Related Questions