Change A Form Background Color To The Desktop Color

The following sample code shows how to retrieve the system’s default background color. There are many other system colors you might like to know about. Here is a list of the Windows 3.1 system colors:

Global Const COLOR_SCROLLBAR = 0
Global Const COLOR_BACKGROUND = 1
Global Const COLOR_ACTIVECAPTION = 2
Global Const COLOR_INACTIVECAPTION = 3
Global Const COLOR_MENU = 4
Global Const COLOR_WINDOW = 5
Global Const COLOR_WINDOWFRAME = 6
Global Const COLOR_MENUTEXT = 7
Global Const COLOR_WINDOWTEXT = 8
Global Const COLOR_CAPTIONTEXT = 9
Global Const COLOR_ACTIVEBORDER = 10
Global Const COLOR_INACTIVEBORDER = 11
Global Const COLOR_APPWORKSPACE = 12
Global Const COLOR_HIGHLIGHT = 13
Global Const COLOR_HIGHLIGHTTEXT = 14
Global Const COLOR_BTNFACE = 15
Global Const COLOR_BTNSHADOW = 16
Global Const COLOR_GRAYTEXT = 17
Global Const COLOR_BTNTEXT = 18
Global Const COLOR_ENDCOLORS = COLOR_BTNTEXT

Declare The Following

Declare Function GetSysColor Lib "User" (ByVal nIndex%) As Long

Code

Sub ColorFormBackground(frmForm as Form)
     Const COLOR_BACKGROUND = 1 'Desktop
     frmForm.BackColor = GetSysColor(COLOR_BACKGROUND)
End Sub

Usage

Private Sub Form_Load()
     ColorFormBackground Me
End Sub

 

This tip is reprinted from the VB Tips & Tricks Volume 1 book.
Parts of this tip was submitted by: Jeff Williams
Compatible With Visual Basic 3.0, Visual Basic 4.0 16-bit
Applies To Forms

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s