I have a control that I need to restrict the types of child controls that it can contain during design time (dragging a new control onto an existing control on the form designer). I tried to do this by overriding the OnControlAdded event:
Protected Overrides Sub OnControlAdded(ByVal e As System.Windows.Forms.ControlEventArgs)
MyBase.OnControlAdded(e)
If e.Control.GetType() IsNot GetType(ExpandablePanel) Then
MsgBox("You can only add the ExpandablePanel control to the TaskPane.", MsgBoxStyle.Exclamation Or MsgBoxStyle.OkOnly, "TaskPane")
Controls.Remove(e.Control)
End If
End Sub
This seems to work, however I get an error message from Visual Studio immediately after the control is removed:
'child' is not a child control of this parent.
What does this mean? How can I accomplish this without errors occurring?