Home
VB.NET
Color Examples
Updated Nov 14, 2023
Dot Net Perls
Color. The world is a colorful place, and in VB.NET we can represent these colors with the Color type. This type is part of the System.Drawing namespace.
The System.Drawing namespace is available on .NET on all platforms, including Windows, macOS and Linux. It makes working with colors easier.
Example. To begin, we must use the "imports" keyword at the top to bring in the System.Drawing namespace. This makes the program compile correctly.
Step 1 On the Color Shared class, we can access different named colors like AliceBlue, a light blue shade.
Step 2 For debugging purposes, we can print the color local variable to the Console.
Step 3 The Color internally keeps track of its ARGB data (which is alpha, red, gree and blue). With properties we can access this information.
Property
Step 4 We print information about the brightness, hue and saturation of the color (which is AliceBlue for this example).
imports System.Drawing Module Module1 Sub Main() ' Step 1: get a color with the Color type. Dim color as Color = Color.AliceBlue ' Step 2: print color. Console.WriteLine(color) ' Step 3: print ARGB data. Console.WriteLine(color.ToArgb()) Console.WriteLine(color.A) Console.WriteLine(color.R) Console.WriteLine(color.G) Console.WriteLine(color.B) ' Step 4: print brightness, hue and saturation data. Console.WriteLine(color.GetBrightness()) Console.WriteLine(color.GetHue()) Console.WriteLine(color.GetSaturation()) End Sub End Module
Color [AliceBlue] -984833 255 240 248 255 0.9705882 208 1
FromName. Suppose we have a name for a color like "white" or "yellow." We can convert this an actual Color type instance with the FromName function.
imports System.Drawing Module Module1 Sub Main() ' Get color from a string. Dim yellow as Color = Color.FromName("yellow") ' Print RGB values for the color. Console.WriteLine(yellow.R) Console.WriteLine(yellow.G) Console.WriteLine(yellow.B) End Sub End Module
255 255 0
Summary. The Color type in VB.NET provides many properties to learn more about a specific color. We can convert colors from Strings with FromName.
Dot Net Perls is a collection of pages with code examples, which are updated to stay current. Programming is an art, and it can be learned from examples.
Donate to this site to help offset the costs of running the server. Sites like this will cease to exist if there is no financial support for them.
Sam Allen is passionate about computer languages, and he maintains 100% of the material available on this website. He hopes it makes the world a nicer place.
This page was last updated on Nov 14, 2023 (new).
Home
Changes
© 2007-2025 Sam Allen