O'Reilly logo

Developing Microsoft® .NET Controls with Microsoft Visual Basic® .NET by John Connell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How ComboBox Draws the Selected Item

In this section, I’ll show you a simple example to demonstrate how the ComboBox control draws each selected item. Draw a combo box on a Windows form, and name it ColorCombo. Add the following code to the form’s Load event handler:

Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load

    Dim aColorName As String
    For Each aColorName In System.Enum.GetNames _
      (GetType(System.Drawing.KnownColor))

        colorcombo.Items.Add(Color.FromName(aColorName))
    Next
    colorcombo.SelectedIndex = 0
End Sub

Running the program provides a list of all the known colors in the .NET Framework, as you can see in Figure 2-25.

Figure 2-25. Enumerating all the .NET colors

In the Load event ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required