Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show all colors

Status
Not open for further replies.

Andrzejek

Programmer
Jan 10, 2006
8,499
5
38
US

I would like to see all available colors and their names on the Form. I know I can do:

[tt]Color.AliceBlue
Color.AntiqueWhite
Color.Aqua
....
Color..YellowGreen[/tt]

but that's a lot of lines of code.

How can I loop thru the colors and display the color and its name in the Grid, for example?

Have fun.

---- Andy
 
Here's a start ...
Code:
        For Each colorName As String In [Enum].GetNames(GetType(KnownColor))
            ListBox1.Items.Add(colorName)
        Next
 

I have this: just a ListBox named lstColor on the Form:
Code:
Imports System.Drawing

Public Class Form1
    Dim kColor As KnownColor

    Private Sub Form1_Load(ByVal sender As Object, _
            ByVal e As System.EventArgs) Handles Me.Load
        For kColor = KnownColor.AliceBlue To KnownColor.YellowGreen
            lstColor.Items.Add(kColor)
        Next
        lstColor.SelectedIndex = 0
    End Sub

    Private Sub lstColor_SelectedIndexChanged(ByVal sender As Object, _
            ByVal e As System.EventArgs) Handles lstColor.SelectedIndexChanged
        Me.BackColor = Color.FromName(Me.lstColor.SelectedItem.ToString)
        Me.Text = lstColor.Text
    End Sub

End Class

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top