<Designer(GetType(MyControlDesigner))> _
Public Class YourParentControl
Inherits System.Windows.Forms.UserControl
+[Windows Generated Code]
Friend Sub OnSelectionChanged()
Dim s as ISelectionService = DirectCast(GetService(GetType(ISelectionService)), ISelectionService)
Dim ct as TheControlYouWantToSelect
Dim ctr as Control
For each ctr in YourControlCollection
If TypeOf ctr is TheControlYouWantToSelect Then
ct = DirectCast(ctr, TheControlYouWantToSelect)
If s.PrimarySelection = ct Then
'Draw your graphics or call your drawing sub
End If
End If
Next
End Sub
Protected Overrides OnMouseDown(ByVal e as MouseEventArgs)
MyBase.OnMouseDown(e)
Dim s as ISelectionService
Dim aList as ArrayList
Dim rect as Rectangle
Dim ct as TheControlYouWantToSelect
Dim ctr as Control
For each Control in YourControlCollection
If TypeOf ctr is TheControlYouWantToSelect
ct = DirectCast(ctr, TheControlYouWantToSelect)
rect = ct.Bounds
If(rect.Contains(e.x, e.y)) Then
s = DirectCast(GetService(GetType(ISelectionService)), ISelectionService)
aList = new ArrayList()
aList.Add(ct)
s.SetSelectedComponents(aList)
Exit For
End If
Next
End Sub
End Class
Public Class MyControlDesigner
Inherits ControlDesigner
Private MyControl as YourParentControl
Public Overrides Sub Initialize(ByVal component as IComponent)
MyBase.Initialize(component)
MyControl = DirectCast(component, YourParentControl)
Dim s as ISelectionService = DirectCast(GetService(GetType(ISelectionService)), ISelectionService)
Dim c as IComponentChangeService = DirectCast(GetService(GetType(IComponentChangeService)), IComponentChangeService)
AddHandler s.SelectionChanged, Addressof OnSelectionChanged
AddHandler c.OnComponentRemoving, Addressof OnComponentRemoving
End Sub
Private Sub OnSelectionChanged(ByVal sender as Object, ByVal e as EventArgs)
MyControl.OnSelectionChanged()
End Sub
'the rest of the designer code
End Class