File size: 25,408 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
Imports System.ComponentModel
Imports System.Drawing.Design
Imports System.Globalization
Imports System.Reflection
Imports System.Xml.Serialization

Namespace PropertyGridEx

    <Serializable(), XmlRootAttribute("CustomProperty")>
    Public Class CustomProperty

#Region "Protected variables"

        ' Common properties
        Protected sName As String = ""
        Protected oValue As Object = Nothing
        Protected bIsReadOnly As Boolean = False
        Protected bVisible As Boolean = True
        Protected sDescription As String = ""
        Protected sCategory As String = ""
        Protected bIsPassword As Boolean = Nothing
        Protected bIsPercentage As Boolean = Nothing
        Protected bParenthesize As Boolean = Nothing

        ' Filename editor properties
        Protected sFilter As String = Nothing
        Protected eDialogType As UIFilenameEditor.FileDialogType = UIFilenameEditor.FileDialogType.LoadFileDialog
        Protected bUseFileNameEditor As Boolean = False

        ' Custom choices properties
        Protected oChoices As CustomChoices = Nothing

        ' Browsable properties
        Protected bIsBrowsable As Boolean = False
        Protected eBrowsablePropertyLabel As BrowsableTypeConverter.LabelStyle = BrowsableTypeConverter.LabelStyle.lsEllipsis

        ' Dynamic properties
        Protected bRef As Boolean = False
        Protected oRef As Object = Nothing
        Protected sProp As String = ""

        ' Databinding properties
        Protected oDatasource As Object = Nothing
        Protected sDisplayMember As String = Nothing
        Protected sValueMember As String = Nothing
        Protected oSelectedValue As Object = Nothing
        Protected oSelectedItem As Object = Nothing
        Protected bIsDropdownResizable As Boolean = Nothing

        ' 3-dots button event handler        
        Protected MethodDelegate As UICustomEventEditor.OnClick

        ' Extended Attributes
        <NonSerialized()> Protected oCustomAttributes As AttributeCollection = Nothing
        Protected oTag As Object = Nothing
        Protected oDefaultValue As Object = Nothing
        Protected oDefaultType As Type = Nothing

        ' Custom Editor and Custom Type Converter
        <NonSerialized()> Protected oCustomEditor As UITypeEditor = Nothing
        <NonSerialized()> Protected oCustomTypeConverter As TypeConverter = Nothing

#End Region

#Region "Public methods"

        Public Sub New()
            sName = "New Property"
            oValue = ""
        End Sub

        Public Sub New(ByVal strName As String, ByVal objValue As Object, Optional ByVal boolIsReadOnly As Boolean = True, Optional ByVal strCategory As String = "", Optional ByVal strDescription As String = "", Optional ByVal boolVisible As Boolean = True)
            sName = strName
            oValue = objValue
            bIsReadOnly = boolIsReadOnly
            sDescription = strDescription
            sCategory = strCategory
            bVisible = boolVisible
            If oValue IsNot Nothing Then
                oDefaultValue = oValue
            End If
        End Sub

        Public Sub New(ByVal strName As String, ByRef objRef As Object, ByVal strProp As String, Optional ByVal boolIsReadOnly As Boolean = True, Optional ByVal strCategory As String = "", Optional ByVal strDescription As String = "", Optional ByVal boolVisible As Boolean = True)
            sName = strName
            bIsReadOnly = boolIsReadOnly
            sDescription = strDescription
            sCategory = strCategory
            bVisible = boolVisible
            bRef = True
            oRef = objRef
            sProp = strProp
            If Value IsNot Nothing Then
                oDefaultValue = Value
            End If
        End Sub

        Public Sub RebuildAttributes()
            If bUseFileNameEditor Then
                BuildAttributes_FilenameEditor()
            ElseIf oChoices IsNot Nothing Then
                BuildAttributes_CustomChoices()
            ElseIf oDatasource IsNot Nothing Then
                BuildAttributes_ListboxEditor()
            ElseIf bIsBrowsable Then
                BuildAttributes_BrowsableProperty()
            End If
        End Sub

#End Region

#Region "Private methods"

        Private Sub BuildAttributes_FilenameEditor()
            Dim attrs As ArrayList = New ArrayList()
            Dim FilterAttribute As New UIFilenameEditor.FileDialogFilterAttribute(sFilter)
            Dim SaveDialogAttribute As New UIFilenameEditor.SaveFileAttribute
            Dim attrArray As Attribute()
            attrs.Add(FilterAttribute)
            If eDialogType = UIFilenameEditor.FileDialogType.SaveFileDialog Then attrs.Add(SaveDialogAttribute)
            attrArray = attrs.ToArray(GetType(Attribute))
            oCustomAttributes = New AttributeCollection(attrArray)
        End Sub

        Private Sub BuildAttributes_CustomChoices()
            If oChoices IsNot Nothing Then
                Dim list As New CustomChoices.CustomChoicesAttributeList(oChoices.Items)
                Dim attrs As ArrayList = New ArrayList()
                Dim attrArray As Attribute()
                attrs.Add(list)
                attrArray = attrs.ToArray(GetType(Attribute))
                oCustomAttributes = New AttributeCollection(attrArray)
            End If
        End Sub

        Private Sub BuildAttributes_ListboxEditor()
            If oDatasource IsNot Nothing Then
                Dim ds As New UIListboxEditor.UIListboxDatasource(oDatasource)
                Dim vm As New UIListboxEditor.UIListboxValueMember(sValueMember)
                Dim dm As New UIListboxEditor.UIListboxDisplayMember(sDisplayMember)
                Dim ddr As UIListboxEditor.UIListboxIsDropDownResizable = Nothing
                Dim attrs As ArrayList = New ArrayList()
                attrs.Add(ds)
                attrs.Add(vm)
                attrs.Add(dm)
                If bIsDropdownResizable Then
                    ddr = New UIListboxEditor.UIListboxIsDropDownResizable
                    attrs.Add(ddr)
                End If
                Dim attrArray As Attribute()
                attrArray = attrs.ToArray(GetType(Attribute))
                oCustomAttributes = New AttributeCollection(attrArray)
            End If
        End Sub

        Private Sub BuildAttributes_BrowsableProperty()
            Dim style As New BrowsableTypeConverter.BrowsableLabelStyleAttribute(eBrowsablePropertyLabel)
            oCustomAttributes = New AttributeCollection(New Attribute() {style})
        End Sub

        Private Sub BuildAttributes_CustomEventProperty()
            Dim attr As New UICustomEventEditor.DelegateAttribute(MethodDelegate)
            oCustomAttributes = New AttributeCollection(New Attribute() {attr})
        End Sub

        Private Property DataColumn() As Object
            Get
                Dim oRow As DataRow = CType(oRef, System.Data.DataRow)
                If oRow.RowState <> DataRowState.Deleted Then
                    If oDatasource Is Nothing Then
                        Return oRow(sProp)
                    Else
                        Dim oLookupTable As DataTable = TryCast(oDatasource, DataTable)
                        If oLookupTable IsNot Nothing Then
                            Return oLookupTable.Select(sValueMember & "=" & oRow(sProp))(0).Item(sDisplayMember)
                        Else
                            Err.Raise(vbObjectError + 513, , "Bind of DataRow with a DataSource that is not a DataTable is not possible")
                            Return Nothing
                        End If
                    End If
                Else
                    Return Nothing
                End If
            End Get
            Set(ByVal value As Object)
                Dim oRow As DataRow = CType(oRef, System.Data.DataRow)
                If oRow.RowState <> DataRowState.Deleted Then
                    If oDatasource Is Nothing Then
                        oRow(sProp) = value
                    Else
                        Dim oLookupTable As DataTable = TryCast(oDatasource, DataTable)
                        If oLookupTable IsNot Nothing Then
                            If oLookupTable.Columns(sDisplayMember).DataType.Equals(System.Type.GetType("System.String")) Then
                                oRow(sProp) = oLookupTable.Select(oLookupTable.Columns(sDisplayMember).ColumnName & " = '" & value & "'")(0).Item(sValueMember)
                            Else
                                oRow(sProp) = oLookupTable.Select(oLookupTable.Columns(sDisplayMember).ColumnName & " = " & value)(0).Item(sValueMember)
                            End If
                        Else
                            Err.Raise(vbObjectError + 514, , "Bind of DataRow with a DataSource that is not a DataTable is impossible")
                        End If
                    End If
                End If
            End Set
        End Property

#End Region

#Region "Public properties"

        <Category("Appearance"),
         DisplayName("Name"),
         DescriptionAttribute("Display Name of the CustomProperty."),
         ParenthesizePropertyName(True),
         XmlElementAttribute("Name")>
        Public Property Name() As String
            Get
                Return sName
            End Get
            Set(ByVal value As String)
                sName = value
            End Set
        End Property

        <Category("Appearance"),
         DisplayName("ReadOnly"),
         DescriptionAttribute("Set read only attribute of the CustomProperty."),
         XmlElementAttribute("ReadOnly")>
        Public Property IsReadOnly() As Boolean
            Get
                Return bIsReadOnly
            End Get
            Set(ByVal value As Boolean)
                bIsReadOnly = value
            End Set
        End Property

        <Category("Appearance"),
         DescriptionAttribute("Set visibility attribute of the CustomProperty.")>
        Public Property Visible() As Boolean
            Get
                Return bVisible
            End Get
            Set(ByVal value As Boolean)
                bVisible = value
            End Set
        End Property

        <Category("Appearance"),
         DescriptionAttribute("Represent the Value of the CustomProperty.")>
        Public Property Value() As Object
            Get
                If bRef Then
                    If TryCast(oRef, DataRow) IsNot Nothing Then
                        Return Me.DataColumn
                    Else
                        Dim method As FieldInfo = oRef.GetType().GetField(sProp)
                        If Not method Is Nothing Then
                            Return method.GetValue(oRef)
                        Else
                            Return oRef.GetType().GetProperty(sProp).GetValue(oRef, Nothing)
                        End If
                    End If
                Else
                    Return oValue
                End If
            End Get
            Set(ByVal value As Object)
                If bRef Then
                    If TryCast(oRef, DataRow) IsNot Nothing Then
                        Me.DataColumn = value
                    Else
                        Dim method As FieldInfo = oRef.GetType().GetField(sProp)
                        If Not method Is Nothing Then
                            method.SetValue(oRef, value)
                        Else
                            oRef.GetType().GetProperty(sProp).SetValue(oRef, value, Nothing)
                        End If
                    End If
                Else
                    oValue = value
                End If
            End Set
        End Property

        <Category("Appearance"),
         DescriptionAttribute("Set description associated with the CustomProperty.")>
        Public Property Description() As String
            Get
                Return sDescription
            End Get
            Set(ByVal value As String)
                sDescription = value
            End Set
        End Property

        <Category("Appearance"),
         DescriptionAttribute("Set category associated with the CustomProperty.")>
        Public Property Category() As String
            Get
                Return sCategory
            End Get
            Set(ByVal value As String)
                sCategory = value
            End Set
        End Property

        <XmlIgnore()>
        Public ReadOnly Property Type() As System.Type
            Get
                If Value IsNot Nothing Then
                    Return Value.GetType
                Else
                    If oDefaultValue IsNot Nothing Then
                        Return oDefaultValue.GetType
                    Else
                        Return oDefaultType
                    End If
                End If
            End Get
        End Property

        <XmlIgnore()>
        Public Property Attributes() As AttributeCollection
            Get
                Return oCustomAttributes
            End Get
            Set(ByVal value As AttributeCollection)
                oCustomAttributes = value
            End Set
        End Property

        <Category("Behavior"),
         DescriptionAttribute("Indicates if the property is browsable or not."),
         XmlElementAttribute(IsNullable:=False)>
        Public Property IsBrowsable() As Boolean
            Get
                Return bIsBrowsable
            End Get
            Set(ByVal value As Boolean)
                bIsBrowsable = value
                If value = True Then
                    BuildAttributes_BrowsableProperty()
                End If
            End Set
        End Property

        <Category("Appearance"),
         DisplayName("Parenthesize"),
         DescriptionAttribute("Indicates whether the name of the associated property is displayed with parentheses in the Properties window."),
         DefaultValue(False),
         XmlElementAttribute("Parenthesize")>
        Public Property Parenthesize() As Boolean
            Get
                Return bParenthesize
            End Get
            Set(ByVal value As Boolean)
                bParenthesize = value
            End Set
        End Property


        <Category("Behavior"),
         DescriptionAttribute("Indicates the style of the label when a property is browsable."),
         XmlElementAttribute(IsNullable:=False)>
        Public Property BrowsableLabelStyle() As BrowsableTypeConverter.LabelStyle
            Get
                Return eBrowsablePropertyLabel
            End Get
            Set(ByVal value As BrowsableTypeConverter.LabelStyle)
                Dim Update As Boolean = False
                If value <> eBrowsablePropertyLabel Then Update = True
                eBrowsablePropertyLabel = value
                If Update Then
                    Dim style As New BrowsableTypeConverter.BrowsableLabelStyleAttribute(value)
                    oCustomAttributes = New AttributeCollection(New Attribute() {style})
                End If
            End Set
        End Property

        <Category("Behavior"),
         DescriptionAttribute("Indicates if the property is masked or not."),
         XmlElementAttribute(IsNullable:=False)>
        Public Property IsPassword() As Boolean
            Get
                Return bIsPassword
            End Get
            Set(ByVal value As Boolean)
                bIsPassword = value
            End Set
        End Property

        <Category("Behavior"),
         DescriptionAttribute("Indicates if the property represents a value in percentage."),
         XmlElementAttribute(IsNullable:=False)>
        Public Property IsPercentage() As Boolean
            Get
                Return bIsPercentage
            End Get
            Set(ByVal value As Boolean)
                bIsPercentage = value
            End Set
        End Property

        <Category("Behavior"),
         DescriptionAttribute("Indicates if the property uses a FileNameEditor converter."),
         XmlElementAttribute(IsNullable:=False)>
        Public Property UseFileNameEditor() As Boolean
            Get
                Return bUseFileNameEditor
            End Get
            Set(ByVal value As Boolean)
                bUseFileNameEditor = value
            End Set
        End Property

        <Category("Behavior"),
         DescriptionAttribute("Apply a filter to FileNameEditor converter."),
         XmlElementAttribute(IsNullable:=False)>
        Public Property FileNameFilter() As String
            Get
                Return sFilter
            End Get
            Set(ByVal value As String)
                Dim UpdateAttributes As Boolean = False
                If value <> sFilter Then UpdateAttributes = True
                sFilter = value
                If UpdateAttributes Then BuildAttributes_FilenameEditor()
            End Set
        End Property

        <Category("Behavior"),
         DescriptionAttribute("DialogType of the FileNameEditor."),
         XmlElementAttribute(IsNullable:=False)>
        Public Property FileNameDialogType() As UIFilenameEditor.FileDialogType
            Get
                Return eDialogType
            End Get
            Set(ByVal value As UIFilenameEditor.FileDialogType)
                Dim UpdateAttributes As Boolean = False
                If value <> eDialogType Then UpdateAttributes = True
                eDialogType = value
                If UpdateAttributes Then BuildAttributes_FilenameEditor()
            End Set
        End Property

        <Category("Behavior"),
         DescriptionAttribute("Custom Choices list."),
         XmlIgnore()>
        Public Property Choices() As CustomChoices
            Get
                Return oChoices
            End Get
            Set(ByVal value As CustomChoices)
                oChoices = value
                BuildAttributes_CustomChoices()
            End Set
        End Property

        <Category("Databinding"),
         XmlIgnore()>
        Public Property Datasource() As Object
            Get
                Return oDatasource
            End Get
            Set(ByVal value As Object)
                oDatasource = value
                BuildAttributes_ListboxEditor()
            End Set
        End Property

        <Category("Databinding"),
         XmlElementAttribute(IsNullable:=False)>
        Public Property ValueMember() As String
            Get
                Return sValueMember
            End Get
            Set(ByVal value As String)
                sValueMember = value
                BuildAttributes_ListboxEditor()
            End Set
        End Property

        <Category("Databinding"),
         XmlElementAttribute(IsNullable:=False)>
        Public Property DisplayMember() As String
            Get
                Return sDisplayMember
            End Get
            Set(ByVal value As String)
                sDisplayMember = value
                BuildAttributes_ListboxEditor()
            End Set
        End Property

        <Category("Databinding"),
         XmlElementAttribute(IsNullable:=False)>
        Public Property SelectedValue() As Object
            Get
                Return oSelectedValue
            End Get
            Set(ByVal value As Object)
                oSelectedValue = value
            End Set
        End Property

        <Category("Databinding"),
         XmlElementAttribute(IsNullable:=False)>
        Public Property SelectedItem() As Object
            Get
                Return oSelectedItem
            End Get
            Set(ByVal value As Object)
                oSelectedItem = value
            End Set
        End Property

        <Category("Databinding"),
         XmlElementAttribute(IsNullable:=False)>
        Public Property IsDropdownResizable() As Boolean
            Get
                Return bIsDropdownResizable
            End Get
            Set(ByVal value As Boolean)
                bIsDropdownResizable = value
                BuildAttributes_ListboxEditor()
            End Set
        End Property

        <XmlIgnore()>
        Public Property CustomEditor() As UITypeEditor
            Get
                Return oCustomEditor
            End Get
            Set(ByVal value As UITypeEditor)
                oCustomEditor = value
            End Set
        End Property

        <XmlIgnore()>
        Public Property CustomTypeConverter() As TypeConverter
            Get
                Return oCustomTypeConverter
            End Get
            Set(ByVal value As TypeConverter)
                oCustomTypeConverter = value
            End Set
        End Property

        <XmlIgnore()>
        Public Property Tag() As Object
            Get
                Return oTag
            End Get
            Set(ByVal value As Object)
                oTag = value
            End Set
        End Property

        <XmlIgnore()>
        Public Property Tag2() As Object

        <XmlIgnore()>
        Public Property Tag3() As Object

        <XmlIgnore()>
        Public Property DefaultValue() As Object
            Get
                Return oDefaultValue
            End Get
            Set(ByVal value As Object)
                oDefaultValue = value
            End Set
        End Property

        <XmlIgnore()>
        Public Property DefaultType() As Type
            Get
                Return oDefaultType
            End Get
            Set(ByVal value As Type)
                oDefaultType = value
            End Set
        End Property

        <XmlIgnore()>
        Public Property OnClick() As UICustomEventEditor.OnClick
            Get
                Return MethodDelegate
            End Get
            Set(ByVal value As UICustomEventEditor.OnClick)
                MethodDelegate = value
                BuildAttributes_CustomEventProperty()
            End Set
        End Property

#End Region

#Region "CustomPropertyDescriptor"
        Public Class CustomPropertyDescriptor
            Inherits PropertyDescriptor

            Protected oCustomProperty As CustomProperty

            Public Sub New(ByVal myProperty As CustomProperty, ByVal attrs() As Attribute)
                MyBase.New(myProperty.Name, attrs)
                If myProperty Is Nothing Then
                    oCustomProperty = Nothing
                Else : oCustomProperty = myProperty
                End If
            End Sub

            Public Overrides Function CanResetValue(ByVal component As Object) As Boolean
                If oCustomProperty.DefaultValue IsNot Nothing OrElse oCustomProperty.DefaultType IsNot Nothing Then
                    Return True
                Else
                    Return False
                End If
            End Function

            Public Overrides ReadOnly Property ComponentType() As System.Type
                Get
                    Return Me.GetType
                End Get
            End Property

            Public Overrides Function GetValue(ByVal component As Object) As Object
                Return oCustomProperty.Value
            End Function

            Public Overrides ReadOnly Property IsReadOnly() As Boolean
                Get
                    Return oCustomProperty.IsReadOnly
                End Get
            End Property

            Public Overrides ReadOnly Property PropertyType() As System.Type
                Get
                    Return oCustomProperty.Type
                End Get
            End Property

            Public Overrides Sub ResetValue(ByVal component As Object)
                oCustomProperty.Value = oCustomProperty.DefaultValue
                Me.OnValueChanged(component, EventArgs.Empty)
            End Sub

            Public Overrides Sub SetValue(ByVal component As Object, ByVal value As Object)
                oCustomProperty.Value = value
                Me.OnValueChanged(component, EventArgs.Empty)
            End Sub

            Public Overrides Function ShouldSerializeValue(ByVal component As Object) As Boolean
                Dim oValue As Object = oCustomProperty.Value
                If oCustomProperty.DefaultValue IsNot Nothing AndAlso
                   oValue IsNot Nothing Then
                    Return Not oValue.Equals(oCustomProperty.DefaultValue)
                Else
                    Return False
                End If
            End Function

            Public Overrides ReadOnly Property Description() As String
                Get
                    Return oCustomProperty.Description
                End Get
            End Property

            Public Overrides ReadOnly Property Category() As String
                Get
                    Return oCustomProperty.Category
                End Get
            End Property

            Public Overrides ReadOnly Property DisplayName() As String
                Get
                    Return oCustomProperty.Name
                End Get
            End Property

            Public Overrides ReadOnly Property IsBrowsable() As Boolean
                Get
                    Return oCustomProperty.IsBrowsable
                End Get
            End Property

            Public ReadOnly Property CustomProperty()
                Get
                    Return oCustomProperty
                End Get
            End Property

        End Class
#End Region

    End Class

End Namespace