I am working on a UserControl and I am looking for a way to prevent developer to place this UserControl more than one time into a form, in Design Time. In other words, how can I detect if my UserControl is already placed into ParentForm or not, in Design Time and prevent the second placement if there is already one there?
I tried something like this example below... First I am not sure if this is the "correct" way and second, I can't find how to remove or stop the placement of UserControl in case there is already one.
Again, all this, in Design Time!!!
vb.net Code:
Private Sub MyUserControl_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim _Count As Integer
Dim _UserControl As MyUserControl
For Each _UserControl In Me.ParentForm.Controls
If _UserControl.Name.Contains("MyUserControl") Then
_Count += 1
End If
Next
If _Count > 1 Then
MsgBox("Control have been placed.")
Else
MsgBox("Control haven't placed yet.")
End If
End Sub