移动是将列表框1中选中的数字移动到列表框2中。
全部是将列表框1中所有数字移动到列表框2中。
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim i As Integer, a As Integer
Randomize()
For i = 0 To 9
a = Int(Rnd() * 90) + 10
ListBox1.Items.Add(a)
Next i
End Sub
'移动按钮
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If ListBox1.SelectedIndex <> -1 Then
ListBox2.Items.Add(ListBox1.SelectedItem)
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
Else
MsgBox("请先进行选择!")
End If
End Sub
'全部按钮
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim n As Integer, i As Integer
n = ListBox1.Items.Count
ListBox2.Items.AddRange(ListBox1.Items)
ListBox1.Items.Clear()
Button1.Enabled = False
Button2.Enabled = False
End Sub
End Class