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

Getting system supported colors.

Author: DevASP
Download Source Code :

This article is about how you can get the color supported by your system and how can use that color to set the color of any control.


Along with you can generate random color to use in your application.


Steps you will do.



Start visual studio and create a new window application.


Set the following properties of the form object.



Name = “frmMain”

FormBorderStyle = “FixedSingle”

MaximizeBox = “False’

Text = “Get System Colors”



Drop a label control and set its following properties. This label is used to display the total number of colors your system support.



Name = “lbColors”

Text = “”



Place a ComboBox control on the form and set its following properties. This ComboBox is used to fill with the name of all system supported colors.



Name = “cbColors”

DropDownStyle = “DropDownList”



Place two button controls and set their properties as below.


First button control.



Name = “btGet”

Text = “Get System Colors”



Second button control.



Name = “btRandom”

Text = “Get Random Colors”



Open the code window of form and write the following code in the click event of btnGet.



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 selected index change event of the ComboBox to change the background color of the form to that of selected.





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


Catch ex As Exception


End Try



Write the following code in the click event of btRandom to generate a random color.



Me.BackColor = GetRandomColor()



Declare a function to; generate 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



Run your application and click the btGet to get the colors and fill the ComboBox with the name of colors. Select any color to change the background color of the form. To generate a random color and set it to the background color of the form click btRandom button.

Add Article Comment:
Name :
Email Address :
Comments :
<< Creating an Application in that will Count number of each character.

Disclaimer - Privacy
© 2002-2017