KnowDotNet NetRefactor

Dealing with Colors in VB.NET

by William Ryan
Print this Article Discuss in Forums

The System.Drawing.Color enumeration in .NET provides a whole host of colors and is very easy to use.  For instance, if I wanted to change the background color of a form, I could use the following:


MyForm.BackGroundColor = Color.White


Anytime an objects property takes a color, this is all you really need to do to maniupate it, provided it's not Read-Only.

Howevever, what if you need a color that's not in the standard enumeration like 192, 192, 192.  You can't pass it in as a string so you need to look to the Color.FromArgb method.  Here's all there is to it:


MyForm.BackgroundColor = Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(255, Byte))

Writing Add-Ins for Visual Studio .NET
Writing Add-ins for Visual Studio .NET
by Les Smith
Apress Publishing