请高手帮助修改一个代码(把一个自定义控件的功能移到窗体上的一个命定中),谢谢!!!
自定义控件B:
Imports System.Windows.Forms
Imports System.ComponentModel
Public Class B
Public Delegate Sub ItemSelectedEventHandler(e As ItemSelectedEventArgs) <Category("Action")> _
Public Event ItemSelected As ItemSelectedEventHandler
Public List As New ComboBox()
Protected Overrides Sub OnClick(e As EventArgs)
MyBase.OnClick(e)
Try
RaiseEvent ItemSelected(New ItemSelectedEventArgs(List.Items(0), 0))
Catch ex As Exception
MsgBox(ex.StackTrace)
End Try
End Sub
End Class
Private _Collection As IList = Nothing
Public Property Collection() As IList
Get
Return _Collection
End Get
Set(value As IList)
_Collection = value
backupList = New ArrayList(value)
ProccessCollection(value)
End Set
End Property
Private Sub ProccessCollection(collection As IList)
B.List.Items.Clear()
B.List.Items.AddRange(CreateNewItemTypes(collection))
End Sub
Public Sub B_ItemSelected(e As ItemSelectedEventArgs) Handles B.ItemSelected
TreeView1.BeginUpdate()
If Collection IsNot Nothing AndAlso e.SelectedItem IsNot Nothing Then
Dim type As Type = DirectCast(e.SelectedItem, Type)
Dim newCollItem As Object = CreateInstance(type)
Dim newTItem As TItem = CreateTItem(newCollItem)
Dim selTItem As TItem = DirectCast(编辑.TreeView1.SelectedNode, TItem)
If selTItem IsNot Nothing Then
Dim position As Integer = 编辑.TreeView1.Nodes.Count
Dim coll As IList
Dim TItemColl As TreeNodeCollection
If selTItem.Parent IsNot Nothing Then
coll = (DirectCast(selTItem.Parent, TItem).SubItems)
TItemColl = selTItem.Parent.Nodes
Else
coll = Collection
TItemColl = 编辑.TreeView1.Nodes
End If
coll.Insert(position, newCollItem)
TItemColl.Insert(position, newTItem)
Else
Collection.Add(newCollItem)
TreeView1.Nodes.Add(newTItem)
End If
TreeView1.SelectedNode = newTItem
End If
TreeView1.EndUpdate()
End Sub
Public Structure ItemSelectedEventArgs '(求教这部分所起的作用)
Private _SelectedItem As Object
Private _SelectedIndex As Integer
Public Sub New(SelectedItem As Object, SelectedIndex As Integer)
Me._SelectedItem = SelectedItem
Me._SelectedIndex = SelectedIndex
End Sub
Public ReadOnly Property SelectedIndex() As Integer
Get
Return _SelectedIndex
End Get
End Property
Public ReadOnly Property SelectedItem() As Object
Get
Return _SelectedItem
End Get
End Property
End Structure