views:

17

answers:

0

I'm just getting started on this, so bear with me. I was looking into writing some macros to provide keyboard shortcuts in the Windows Forms Designer in Visual Studio. In particular I was hoping to create shortcuts for manipulating certain properties of the selected control in the designer. Obviously to do this I need to somehow access the control.

I was following the steps outlined here, but I've hit a wall. I tried this line:

Dim selectionService = TryCast( _
    serviceProvider.GetService(GetType(ISelectionService)), _
    ISelectionService _
)

But that actually threw an InvalidCastException, which surprised me greatly (since I was using TryCast). I also tried commenting out that line and skipping straight ahead to:

Dim container = TryCast(designerHost.Container, IContainer)
Dim components = TryCast(container.Components, ComponentCollection)

But this, too, threw an InvalidCastException. It seems these COM objects are tricky devils. Can anyone point me in the right direction here?