WindowsForms Designer stuff (yet again)
I'm still sitting around working on my control and found another cool service you can access from your designer. It's the ISelectionService.
What this will do for you is give you access to the item(s) in the current designer that are selected, whether it be your form, a component in the component tray or a few buttons on your form.
I recently needed this so that I could hide a DesignerVerb (i.e. a menu item when you right mouse click on anything in the designer) to only show up only when controls on the parent form were selected. So in comes ISelectionService to the rescue providing me with a SelectionChanged Event to grab onto and make the appropriate changes to my DesignerVerb (showing it or not showing it). Here's a little code on how to set up the EventHandler and then displaying how many items are currently selected in the designer.
Private
SService As ISelectionService
Public
Overrides Sub Initialize(ByVal component As System.ComponentModel.IComponent)
MyBase.Initialize(component)
SService = DirectCast(MyBase.GetService(GetType(ISelectionService)), ISelectionService)
AddHandler SService.SelectionChanged, AddressOf Parent_SelectionChanged
End Sub
Private
Sub Parent_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs)
MessageBox.Show(SService.SelectionCount.ToString)
End Sub
Again, I'll be posting this control (and all its code) when it's completed, but I'm just working out a few kinks right now. For any of you curious as to what this control is: It's a ControlArray Component with full design time support. All you ex-VB6'ers out there know what I'm talking about! ;) I think this will be a helpful component to all and should be a good learning tool too, since all the source will be included!
Btw, do we have any designer serialization experts in here? Anyone know how to force the designer to serialize a property?