16,555
社区成员
发帖
与我相关
我的任务
分享
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
问题解决了吗? 求助 我也遇到了
Public Class CheckedListBoxUITypeEditor
Inherits System.Drawing.Design.UITypeEditor
Private Sub New()
cbx = New CheckedListBox()
End Sub
End Class
只有第一个控件才走这里的new,以后new出来的控件不走这个new了,但是呢,这个调用是用的
<EditorAttribute(GetType(CheckedListBoxUITypeEditor), GetType(System.Drawing.Design.UITypeEditor))>
,不知道这里要怎么修改才能让CheckedListBoxUITypeEditor每次都走new了