O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Use System Colors

Problem

You want to use system-defined colors when drawing.

Solution

Use the properties of the System.Drawing.SystemColors class.

Discussion

When mixing standard Windows interface elements with your own drawing code, you need to take special care that you follow the system color scheme. Otherwise, you might end up with illegible text—or just garishly ugly windows.

Retrieving system color information is easy. You can simply use the shared properties of the System.Drawing.SystemColors class. In addition, you can use the System.Drawing.KnownColors enumeration to retrieve a list of friendly (human-readable) color names and system color names.

Here’s an example that draws text on a form using the background and foreground colors of the form ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required