Public Class frmDemo

  Private Sub frmDemo_Load(ByVal sender As System.Object,
                           ByVal e As System.EventArgs) Handles MyBase.Load
    lstOutput.Items.Add("makes")
    lstOutput.Items.Add("haste")
    lstOutput.Items.Add("waste")
  End Sub

  Private Sub mnuOrderAsc_Click(ByVal sender As System.Object,
                                ByVal e As System.EventArgs) Handles mnuOrderAsc.Click
    lstOutput.Sorted = True
  End Sub

  Private Sub mnuOrderDesc_Click(ByVal sender As System.Object,
                                 ByVal e As System.EventArgs) Handles mnuOrderDesc.Click
    'This code uses the fact that if a list is in ascending order,
    'then reading it backwards gives a descending list
    Dim temp(2) As String     'Hold ascending array of items
    lstOutput.Sorted = True   'Sort the items alphabetically
    For i As Integer = 0 To 2            'Place sorted items into the array
      temp(i) = CStr(lstOutput.Items(i))
    Next
    lstOutput.Sorted = False  'Turn off the Sorted property
    lstOutput.Items.Clear()
    For i As Integer = 2 To 0 Step -1
      lstOutput.Items.Add(temp(i))
    Next
  End Sub

  Private Sub mnuColorForeRed_Click(ByVal sender As System.Object,
                                    ByVal e As System.EventArgs) Handles mnuColorForeRed.Click
    lstOutput.ForeColor = Color.Red
  End Sub

  Private Sub mnuColorForeBlue_Click(ByVal sender As System.Object,
                                     ByVal e As System.EventArgs) Handles mnuColorForeBlue.Click
    lstOutput.ForeColor = Color.Blue
  End Sub

  Private Sub mnuColorBackYellow_Click(ByVal sender As System.Object,
                                       ByVal e As System.EventArgs) Handles mnuColorBackYellow.Click
    'Make Yellow the background color of the list box, guarantee that a
    'check mark appears in front of the menu item Yellow and not in front
    'of the White menu item
    lstOutput.BackColor = Color.Yellow
    mnuColorBackYellow.Checked = True
    mnuColorBackWhite.Checked = False
  End Sub

  Private Sub mnuColorBackWhite_Click(ByVal sender As System.Object,
                                      ByVal e As System.EventArgs) Handles mnuColorBackWhite.Click
    lstOutput.BackColor = Color.White
    mnuColorBackYellow.Checked = False
    mnuColorBackWhite.Checked = True
  End Sub

End Class
