I have a user control in my project and I want when I click on a button to add this user control to a form, but if the user control is already in the form I want to show it.
This the code I wrote so far:
Using GstAbonnement As New GestionAbonnement
GstAbonnement.Dock = DockStyle.Fill
Me.Controls.Add(GstAbonnement)
End Using
How can I test if the user control is already in the form or not ?
With your current code, that control will never be found in the form because the
Using...End Usingsyntax with dispose of the control.Try changing it to this:
Notice I supplied a name for the control.
Now you can simply check the key if the control was in the collection or not: