Public Class UserControlMultiListBox
Inherits System.Windows.Forms.UserControl
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'UserControl overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents lstLeft As System.Windows.Forms.ListBox
Friend WithEvents lstRight As System.Windows.Forms.ListBox
Friend WithEvents btnRightOne As System.Windows.Forms.Button
Friend WithEvents btnRightMul As System.Windows.Forms.Button
Friend WithEvents btnLeftOne As System.Windows.Forms.Button
Friend WithEvents btnLeftMul As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.lstLeft = New System.Windows.Forms.ListBox
Me.lstRight = New System.Windows.Forms.ListBox
Me.btnRightOne = New System.Windows.Forms.Button
Me.btnRightMul = New System.Windows.Forms.Button
Me.btnLeftOne = New System.Windows.Forms.Button
Me.btnLeftMul = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(6, 7)
Me.Label1.Name = "Label1"
Me.Label1.TabIndex = 0
Me.Label1.Text = "现有项目"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(181, 7)
Me.Label2.Name = "Label2"
Me.Label2.TabIndex = 1
Me.Label2.Text = "选择项目"
'
'lstLeft
'
Me.lstLeft.ItemHeight = 12
Me.lstLeft.Location = New System.Drawing.Point(6, 31)
Me.lstLeft.Name = "lstLeft"
Me.lstLeft.Size = New System.Drawing.Size(120, 136)
Me.lstLeft.Sorted = True
Me.lstLeft.TabIndex = 2
'
'lstRight
'
Me.lstRight.ItemHeight = 12
Me.lstRight.Location = New System.Drawing.Point(182, 31)
Me.lstRight.Name = "lstRight"
Me.lstRight.Size = New System.Drawing.Size(120, 136)
Me.lstRight.Sorted = True
Me.lstRight.TabIndex = 3
'
'btnRightOne
'
Me.btnRightOne.Location = New System.Drawing.Point(134, 47)
Me.btnRightOne.Name = "btnRightOne"
Me.btnRightOne.Size = New System.Drawing.Size(40, 23)
Me.btnRightOne.TabIndex = 4
Me.btnRightOne.Text = ">"
'
'btnRightMul
'
Me.btnRightMul.Location = New System.Drawing.Point(134, 77)
Me.btnRightMul.Name = "btnRightMul"
Me.btnRightMul.Size = New System.Drawing.Size(40, 23)
Me.btnRightMul.TabIndex = 5
Me.btnRightMul.Text = ">>"
'
'btnLeftOne
'
Me.btnLeftOne.Location = New System.Drawing.Point(134, 106)
Me.btnLeftOne.Name = "btnLeftOne"
Me.btnLeftOne.Size = New System.Drawing.Size(40, 23)
Me.btnLeftOne.TabIndex = 6
Me.btnLeftOne.Text = "<"
'
'btnLeftMul
'
Me.btnLeftMul.Location = New System.Drawing.Point(134, 135)
Me.btnLeftMul.Name = "btnLeftMul"
Me.btnLeftMul.Size = New System.Drawing.Size(40, 23)
Me.btnLeftMul.TabIndex = 7
Me.btnLeftMul.Text = "<<"
'
'UserControlMultiListBox
'
Me.Controls.Add(Me.btnLeftMul)
Me.Controls.Add(Me.btnLeftOne)
Me.Controls.Add(Me.btnRightMul)
Me.Controls.Add(Me.btnRightOne)
Me.Controls.Add(Me.lstRight)
Me.Controls.Add(Me.lstLeft)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Name = "UserControlMultiListBox"
Me.Size = New System.Drawing.Size(306, 176)
Me.ResumeLayout(False)
End Sub
#End Region
Public Property labelLeftText() As String
Get
Return Label1.Text.ToString
End Get
Set(ByVal Value As String)
Label1.Text = Value
End Set
End Property
Public Property labelRightText() As String
Get
Return Label2.Text.ToString
End Get
Set(ByVal Value As String)
Label2.Text = Value
End Set
End Property
Public ReadOnly Property LeftListBoxItems() As ListBox.ObjectCollection
Get
Return lstLeft.Items
End Get
End Property
Public ReadOnly Property RightListBoxItems() As ListBox.ObjectCollection
Get
Return lstRight.Items
End Get
End Property
Public Property ListBoxSelectMode() As SelectionMode
Get
Return lstLeft.SelectionMode
End Get
Set(ByVal Value As SelectionMode)
lstRight.SelectionMode = Value
lstLeft.SelectionMode = Value
End Set
End Property
Public Sub RightMoveOne()
Dim e As System.EventArgs
btnRightOne_Click(btnRightOne, e)
End Sub
Public Sub RightMoveMul()
Dim e As System.EventArgs
btnRightMul_Click(btnRightMul, e)
End Sub
Public Sub LeftMoveOne()
Dim e As System.EventArgs
btnLeftOne_Click(btnLeftOne, e)
End Sub
Public Sub LeftMoveMul()
Dim e As System.EventArgs
btnLeftMul_Click(btnLeftMul, e)
End Sub
Public Event ItemMoved(ByVal sender As Object, ByVal nLeft As Integer, ByVal nRight As Integer, ByVal nDirection As Integer)
Private Sub btnRightOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRightOne.Click
If lstLeft.Items.Count > 0 And lstLeft.SelectedIndex <> -1 Then
Dim selectItem As Object
Dim selectItems As New Collection
Try
For Each selectItem In lstLeft.SelectedItems
lstRight.Items.Add(selectItem)
selectItems.Add(selectItem)
Next
For Each selectItem In selectItems
lstLeft.Items.Remove(selectItem)
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub
Private Sub btnLeftOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLeftOne.Click
If lstRight.Items.Count > 0 And lstRight.SelectedIndex <> -1 Then
Dim selectItem As Object
Dim selectItems As New Collection
Try
For Each selectItem In lstRight.SelectedItems
lstLeft.Items.Add(selectItem)
selectItems.Add(selectItem)
Next
For Each selectItem In selectItems
lstRight.Items.Remove(selectItem)
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
selectItems = Nothing
End If
End Sub
Private Sub btnRightMul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRightMul.Click
With lstLeft
If .Items.Count > 0 Then
Dim oItem As Object
For Each oItem In .Items
lstRight.Items.Add(oItem)
Next
.Items.Clear()
End If
End With
End Sub
Private Sub btnLeftMul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLeftMul.Click
With lstRight
If .Items.Count > 0 Then
Dim oItem As Object
For Each oItem In .Items
lstLeft.Items.Add(oItem)
Next
.Items.Clear()
End If
End With
End Sub
End Class
界面设计