Writing UI Type Editors?

Merrion

Well-known member
Joined
Sep 29, 2001
Messages
265
Location
Dublin, Ireland
User Rank
*Experts*
Has anyone got this to work?

I have a UI editor class defined thus:-
Code:
Public Class HotkeyUIEditor
    Inherits UITypeEditor

    Public Overloads Function GetEditStyle() As UITypeEditorEditStyle
        \\ The hotkeys are listed in a dropdown list
        Return UITypeEditorEditStyle.DropDown
    End Function


    <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
    Public Overloads Overrides Function EditValue(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal provider As System.IServiceProvider, ByVal value As Object) As Object
        \\ Return the value if the value is not of type Keys...
        If Not value.GetType() Is GetType(Keys) Then
            Return value
        End If
         Uses the IWindowsFormsEditorService to display a 
         drop-down UI in the Properties window.
        Dim edSvc As IWindowsFormsEditorService = CType(provider.GetService(GetType(IWindowsFormsEditorService)), IWindowsFormsEditorService)

        If Not (edSvc Is Nothing) Then
             Display an angle selection control and retrieve the value.
            Dim kbdControl As New KeyboardControl(CType(value, Keys))
            edSvc.DropDownControl(kbdControl)

             Return the value in the appropraite data format.
            Return kbdControl.SelectedKey

        End If
        Return value
    End Function
End Class

And the component that this is supposed to edit is thus...
Code:
<ToolboxBitmap(GetType(SystemWideHotkeyComponent), "toolboximage")> _
Public Class SystemWideHotkeyComponent
    Inherits Component

-- stuff 

   <DefaultValue(Keys.A), _
    Editor(GetType(HotkeyUIEditor), _
        GetType(UITypeEditor))> _
        Public Property HotKey() As Keys
        Get
            Return mHotkey
        End Get
        Set(ByVal Value As Keys)
            If Value = Keys.F12 Then
                Throw New ArgumentException("The F12 key is reserved for the use of the system debugger")
            ElseIf Value = Keys.Alt Then
                Throw New ArgumentException("The ALT key can only be used as a modifier - set .AltKey=True ")
            ElseIf Value = Keys.Shift Then
                Throw New ArgumentException("The SHIFT key can only be used as a modifier - set .AltKey=True ")
            ElseIf Value = Keys.Control Then
                Throw New ArgumentException("The CONTROL key can only be used as a modifier - set .AltKey=True ")
            Else
                If Value <> mHotkey Then
                    mHotkey = Value
                    Call StartHotkeyWatch()
                End If
            End If
        End Set
    End Property
End Class

But in Visual Studio when I bring up the properties for the component, no custom UI editor is shown. Any ideas?
 
Back
Top