Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
SQL Server

How to Check that how many colors your System supports

Author: DevASP
Download Source Code :

This article is about how you can get all the colors supported by the system.

  • Steps you will do.
  • Start visual studio and create a new window application
  • Set the following properties of the form
Name = frmMain, Text = Get System Colors


  • Now drop a label control on your form and set the following properties of it.
Name = lbColors, Text = “”


  • Drop a ComboBox control on the form and set following properties.
Name = cbColors, Text = “”, DropDrownStyle = DropDrownList


  • Place two button controls on the form and set their properties respectively as below:

Frist, Name = btGet, Text = Get all system colors


Second, Name = btRand, Text = Get random color


  • Now open the code window and write the following code in the click event of the first button to get all the system colors.

Dim color As Color

Dim i As Integer


For Each color In



i += 1





lbColors.Text = "Total Color Count: " & i

cbColors.SelectedIndex = 0


Me.BackColor = color.FromKnownColor(cbColors.SelectedItem)



  • Write the following code in the selectedindexchanged event of the combobox. So that when you will change the combobox index the selected color will be the back color of form.




 Me.BackColor = Color.FromKnownColor(cbColors.SelectedItem)


Catch ex As Exception




End Try


  • Write a function to get the random color as below:

Function GetRandomColor() As Color


 Dim rand As New Random


 Return Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256))


End Function


  • Now in the click event of the second button write the following code to get the random colors.
Me.BackColor = GetRandomColor()
Add Article Comment:
Name :
Email Address :
Comments :
<< How to Count number of Alphabets in a Text File

Disclaimer - Privacy
© 2002-2017