' ListboxQuickyDemo.vb.txt Imports cc = Microsoft.VisualBasic.ControlChars Public Class ListboxQuickyDemo Inherits System.Windows.Forms.Form #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 'Form 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 lb As System.Windows.Forms.ListBox Friend WithEvents btnManny As System.Windows.Forms.Button Friend WithEvents btnMoe As System.Windows.Forms.Button Friend WithEvents btnJack As System.Windows.Forms.Button Friend WithEvents lblPepBoy As System.Windows.Forms.Label Friend WithEvents btnClear As System.Windows.Forms.Button Private Sub InitializeComponent() Me.lb = New System.Windows.Forms.ListBox Me.btnManny = New System.Windows.Forms.Button Me.btnMoe = New System.Windows.Forms.Button Me.btnJack = New System.Windows.Forms.Button Me.lblPepBoy = New System.Windows.Forms.Label Me.btnClear = New System.Windows.Forms.Button Me.SuspendLayout() ' 'lb ' Me.lb.Location = New System.Drawing.Point(96, 16) Me.lb.Name = "lb" Me.lb.SelectionMode = System.Windows.Forms.SelectionMode.MultiSimple Me.lb.Size = New System.Drawing.Size(72, 82) Me.lb.TabIndex = 0 ' 'btnManny ' Me.btnManny.Location = New System.Drawing.Point(8, 16) Me.btnManny.Name = "btnManny" Me.btnManny.TabIndex = 1 Me.btnManny.Text = "Manny" ' 'btnMoe ' Me.btnMoe.Location = New System.Drawing.Point(8, 48) Me.btnMoe.Name = "btnMoe" Me.btnMoe.TabIndex = 2 Me.btnMoe.Text = "Moe" ' 'btnJack ' Me.btnJack.Location = New System.Drawing.Point(8, 80) Me.btnJack.Name = "btnJack" Me.btnJack.TabIndex = 3 Me.btnJack.Text = "Jack" ' 'lblPepBoy ' Me.lblPepBoy.Font = New System.Drawing.Font("Courier New", 14.25!, CType((System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Italic), System.Drawing.FontStyle), System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblPepBoy.Location = New System.Drawing.Point(16, 120) Me.lblPepBoy.Name = "lblPepBoy" Me.lblPepBoy.Size = New System.Drawing.Size(256, 120) Me.lblPepBoy.TabIndex = 4 Me.lblPepBoy.Text = "None of the above..." ' 'btnClear ' Me.btnClear.Location = New System.Drawing.Point(184, 72) Me.btnClear.Name = "btnClear" Me.btnClear.TabIndex = 5 Me.btnClear.Text = "Clear" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 273) Me.Controls.Add(Me.btnClear) Me.Controls.Add(Me.lblPepBoy) Me.Controls.Add(Me.btnJack) Me.Controls.Add(Me.btnMoe) Me.Controls.Add(Me.btnManny) Me.Controls.Add(Me.lb) Me.Name = "Form1" Me.Text = "Listbox Quicky Demo" Me.ResumeLayout(False) End Sub #End Region Private Sub ButtonHandler(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnManny.Click, btnMoe.Click, btnJack.Click Dim btn As Button = CType(sender, Button) Dim strPepBoy As String Select Case True Case btn Is btnManny strPepBoy = "Manny" Case btn Is btnMoe strPepBoy = "Moe" Case btn Is btnJack strPepBoy = "Jack" End Select lb.Items.Add(strPepBoy) btnClear.Visible = True End Sub Private Sub lb_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lb.SelectedIndexChanged Dim strPepBoy As String Dim intCount As Integer = lb.SelectedItems.Count Select Case intCount Case 0 strPepBoy = "None of the above..." Case 1 strPepBoy = lb.SelectedItems.Item(0) Case 2 To 4 Dim i As Integer strPepBoy = "=====================" & cc.NewLine For i = 0 To intCount - 1 strPepBoy &= lb.SelectedItems.Item(i) & cc.NewLine Next strPepBoy &= "=====================" Case Else strPepBoy = "Stop already!!!" End Select lblPepBoy.Text = strPepBoy End Sub Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click lblPepBoy.Text = "" If lb.Items.Count > 0 Then lb.Items.RemoveAt(0) Else btnClear.Visible = False End If End Sub End Class