UITypeEditor设置属性的时候,使用了同一个对象
Imports System
Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.Globalization
Imports System.IO
Imports System.Linq
Imports System.Reflection
Imports System.Runtime.CompilerServices
Imports System.Security
Imports System.Text
Imports System.Threading.Tasks
Imports Microsoft.VisualBasic
Public Class CheckedListBoxEditor
Private _strValue As String = "(Collection)"
Private _strValue2 As String = "(Collection)"
<Description("This property contains the checked listbox collection.")>
<EditorAttribute(GetType(CheckedListBoxUITypeEditor), GetType(System.Drawing.Design.UITypeEditor))>
Public Property CheckedListBoxCollectionProperty As String
Get
Return _strValue
End Get
Set(ByVal value As String)
_strValue = "(Collection)"
End Set
End Property
<Description("This property contains the checked listbox collection.")>
<EditorAttribute(GetType(CheckedListBoxUITypeEditor), GetType(System.Drawing.Design.UITypeEditor))>
Public Property CheckedListBoxCollectionProperty2 As String
Get
Return _strValue2
End Get
Set(ByVal value As String)
_strValue2 = "(Collection)"
End Set
End Property
End Class
Public Class CheckedListBoxUITypeEditor
Inherits System.Drawing.Design.UITypeEditor
Private Sub New()
cbx = New CheckedListBox()
End Sub
Private _cbx As CheckedListBox
Public Property cbx As CheckedListBox
<MethodImpl(MethodImplOptions.Synchronized)>
Get
Return _cbx
End Get
<MethodImpl(MethodImplOptions.Synchronized)>
Set(ByVal value As CheckedListBox)
If _cbx IsNot Nothing Then
_cbx.Leave -= AddressOf bx_Leave
End If
_cbx = value
If _cbx IsNot Nothing Then
_cbx.Leave += AddressOf bx_Leave
End If
End Set
End Property
Private es As IWindowsFormsEditorService
Public Overloads Overrides Function GetEditStyle(ByVal context As System.ComponentModel.ITypeDescriptorContext) As System.Drawing.Design.UITypeEditorEditStyle
Return System.Drawing.Design.UITypeEditorEditStyle.DropDown
End Function
Public Overloads Overrides ReadOnly Property IsDropDownResizable As Boolean
Get
Return True
End Get
End Property
Public Overloads Overrides Function EditValue(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal provider As System.IServiceProvider, ByVal value As Object) As Object
es = CType(provider.GetService(GetType(IWindowsFormsEditorService)), IWindowsFormsEditorService)
If es IsNot Nothing Then
LoadListBoxItems()
cbx.Sorted = True
es.DropDownControl(cbx)
End If
Return Nothing
End Function
Private Sub bx_Leave(ByVal sender As Object, ByVal e As System.EventArgs)
My.Settings.UrlsList.Clear()
If True Then
Dim withBlock = cbx
For i As Integer = 0 To withBlock.Items.Count - 1
Dim txt As String = withBlock.Items(i).ToString
Dim chk As String = withBlock.GetItemChecked(i).ToString
Dim combined As String = Strings.LCase(txt) & "," + Strings.LCase(chk)
If withBlock.Items(i).ToString <> "" Then My.Settings.UrlsList.Add(combined)
Next
End If
My.Settings.Save()
End Sub
Private Sub LoadListBoxItems()
Dim a As ArrayList = New ArrayList()
For Each s As String In My.Settings.UrlsList
a.Add(Strings.Split(s, ","))
Next
Dim h As Hashtable = New Hashtable()
For i As Integer = 0 To a.Count - 1
h.Add(CType(a.Item(i).GetValue(0).ToString, Array), CType(a.Item(i).GetValue(1).ToString, Array))
Next
a = Nothing
cbx.Items.Clear()
For Each de As DictionaryEntry In h
cbx.Items.Add(de.Key, System.Convert.ToBoolean(de.Value))
Next
h = Nothing
End Sub
End Class
如上代码,属性 CheckedListBoxCollectionProperty 和 CheckedListBoxCollectionProperty2 单独是可以使用的,但是,CheckedListBoxCollectionProperty 里变更时,在 CheckedListBoxCollectionProperty2 属性里也变更成和 CheckedListBoxCollectionProperty 一样了。看起来 CheckedListBoxUITypeEditor 只生成了一个对象,被两个属性共用,希望两个属性单独使用自己的 CheckedListBoxUITypeEditor 对象,需要怎么修改呢?
...全文
相关推荐
C# 自定义属性编辑器(UITypeEditor )
通过自定义UITypeEditor,我们可以为控件、类或其他类型的属性创建定制的编辑界面,使得在设计时能够以更加直观和高效的方式设置属性值。
winform自定义控件(gdi+)(4)———UITypeEditor为自定义类型属性添加自定义编辑界面
UITypeEditor 是一个位于 System.Drawing.Design 命名空间的抽象类。它的核心目的是:在 Visual Studio 的属性设计器中提供一个自定义的、可视化的编辑界面,当默认的属性编辑方式(文本框、下拉框)不够用时,你就可以使用 UITypeEditor。
vb.net 自定义控件(含自定义对话框设置属性) 实例
vb.net 自定义控件 自定义属性 UITypeEditor UI 类型编辑器 实例提供一个示例 UITypeEditor,它使用 IWindowsFormsEditorService 显示用于用户
C# 自定义属性在propertyGrid控件中显示 演示demo
为了使`PropertyGrid`能够识别并使用这些自定义属性,我们需要设置`PropertyGrid`的`DataSource`属性为我们的`Person`实例,并启用`AutoGenerateProperties
Winform 属性编辑器 propertyGrid示例 下拉列表框
通过将对象实例传递给`PropertyGrid`的`SelectedObject`属性,`PropertyGrid`会自动显示该对象的所有公共属性,并允许用户进行编辑。



