File size: 2,491 Bytes
b1b3bae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Imports System.ComponentModel
Imports System.Drawing.Design
Imports System.Windows.Forms

Namespace PropertyGridEx
    Public Class UICustomEventEditor
        Inherits System.Drawing.Design.UITypeEditor

        Public Delegate Function OnClick(ByVal sender As Object, ByVal e As EventArgs) As Object
        Protected m_MethodDelegate As UICustomEventEditor.OnClick
        Protected m_sender As CustomProperty.CustomPropertyDescriptor

        Public Overloads Overrides Function GetEditStyle(ByVal context As _
                        ITypeDescriptorContext) As UITypeEditorEditStyle
            If Not context Is Nothing AndAlso Not context.Instance Is Nothing Then
                If Not context.PropertyDescriptor.IsReadOnly Then
                    Return UITypeEditorEditStyle.Modal
                End If
            End If
            Return UITypeEditorEditStyle.None
        End Function

        <RefreshProperties(RefreshProperties.All)> _
        Public Overloads Overrides Function EditValue( _
                    ByVal context As ITypeDescriptorContext, _
                    ByVal provider As System.IServiceProvider, _
                    ByVal value As [Object]) As [Object]
            If context Is Nothing OrElse provider Is Nothing _
                    OrElse context.Instance Is Nothing Then
                Return MyBase.EditValue(provider, value)
            End If
            If m_MethodDelegate Is Nothing Then
                Dim attr As DelegateAttribute = context.PropertyDescriptor.Attributes(GetType(DelegateAttribute))
                m_MethodDelegate = attr.GetMethod
            End If
            If m_sender Is Nothing Then
                m_sender = TryCast(context.PropertyDescriptor, CustomProperty.CustomPropertyDescriptor)
            End If
            Return m_MethodDelegate.Invoke(m_sender, Nothing)
        End Function

        <AttributeUsage(AttributeTargets.Property)> _
    Public Class DelegateAttribute
            Inherits Attribute
            Protected m_MethodDelegate As UICustomEventEditor.OnClick

            Public ReadOnly Property GetMethod() As UICustomEventEditor.OnClick
                Get
                    Return Me.m_MethodDelegate
                End Get
            End Property

            Public Sub New(ByVal MethodDelegate As UICustomEventEditor.OnClick)
                MyBase.New()
                Me.m_MethodDelegate = MethodDelegate
            End Sub
        End Class

    End Class
End Namespace