双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

UITypeEditor设置属性的时候,使用了同一个对象

李察德-泰森 李察德-泰森 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

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 对象,需要怎么修改呢?
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
李察德-泰森
VB 16,718 成员 110,520 内容