Zebra0.com

Learn to Program Step-by-Step

Hobbies

Adding hobbies to a list box.

Hobbies

We use an input box to get a hobby from the user and add it to the list box.

Public Class Form1
    'your name
    Private Sub BtnAdd_Click(sender As Object, e As EventArgs) Handles BtnAdd.Click
        'ask user for hobby, add to list
        Dim hobby As String
        hobby = InputBox("Enter a hobby", "Hobby")
        If hobby <> "" Then
            LstHobbies.Items.Add(hobby)
        End If

    End Sub

    Private Sub LstHobbies_SelectedIndexChanged(sender As Object, e As EventArgs) Handles LstHobbies.SelectedIndexChanged
        Me.Text = "I like " + LstHobbies.Text + " too!"
    End Sub

    Private Sub BtnExit_Click(sender As Object, e As EventArgs) Handles BtnExit.Click
        End
    End Sub

    Private Sub BtnAdd_MouseEnter(sender As Object, e As EventArgs) Handles BtnAdd.MouseEnter
        Me.BackColor = Color.Blue
    End Sub
End Class


Download Source file
Lesson
Last modified: January 30 2025 14:19:27.