-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomColorizerEditor.vb
59 lines (51 loc) · 2.59 KB
/
CustomColorizerEditor.vb
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
Imports DevExpress.XtraCharts
Imports DevExpress.XtraCharts.Designer
Imports DevExpress.XtraEditors
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing.Design
Imports System.Windows.Forms.Design
Imports CustomChartElementModel.Form1
Namespace CustomChartElementModel
Public Class CustomColorizerEditor
Inherits UITypeEditor
Private editorService As IWindowsFormsEditorService
Public Overrides Function EditValue(ByVal context As ITypeDescriptorContext, ByVal provider As IServiceProvider, ByVal value As Object) As Object
editorService = CType(provider.GetService(GetType(IWindowsFormsEditorService)), IWindowsFormsEditorService)
Dim seriesView = TryCast(context.Instance, SeriesViewBaseModel)
Dim colorizers As List(Of ChartColorizerBase) = GetColorizers()
Dim modelProvider As CustomModelProvider = New CustomModelProvider()
modelProvider.RegisterCustomModelType(GetType(CustomPointColorizer), GetType(CustomPointColorizerModel))
Dim listBox = New ListBoxControl()
AddHandler listBox.Click, AddressOf listBox_Click
listBox.Items.Add("(None)")
For Each colorizer As ChartColorizerBase In colorizers
Dim colorizerModel = ModelHelper.GetModel(Of ChartColorizerBaseModel)(colorizer, modelProvider)
Dim index As Integer = listBox.Items.Add(colorizerModel)
If value IsNot Nothing AndAlso colorizerModel.GetType() Is value.GetType() Then
listBox.SelectedIndex = index
End If
Next
editorService.DropDownControl(listBox)
If listBox.SelectedIndex <> 0 Then
If value Is Nothing OrElse listBox.SelectedItem.GetType() IsNot value.GetType() Then
Return listBox.SelectedItem
Else
Return value
End If
Else
Return Nothing
End If
End Function
Private Sub listBox_Click(ByVal sender As Object, ByVal e As EventArgs)
editorService.CloseDropDown()
End Sub
Private Function GetColorizers() As List(Of ChartColorizerBase)
Return New List(Of ChartColorizerBase)() From {New CustomPointColorizer(), New KeyColorColorizer(), New RangeColorizer()}
End Function
Public Overrides Function GetEditStyle(ByVal context As ITypeDescriptorContext) As UITypeEditorEditStyle
Return UITypeEditorEditStyle.DropDown
End Function
End Class
End Namespace