自定义控件

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

界面设计

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值