February 28, 1996
The Microsoft® Visual Basic® version 4.0 Setup program allows you to create a standard installation program for your Visual Basic application. The Setup program, as with other Microsoft Setup programs, draws a gradient background pattern, usually in a blue color. This article explains how to draw gradient backgrounds in a Visual Basic application.
Most Microsoft® Windows® applications are installed by running a Setup program. These setup programs often display a window in which appears a faded blue background. This same effect can be reproduced in Microsoft Visual Basic® version 4.0 applications by using the Windows application programming interface (API) RealizePalette function.
To display a window with a gradient background, you simply paint thin rectangles in different colors on the form. This gives the form a fade-to-black effect.
The RealizePalette function lets you select a logical palette for a device context, such as a window. This allows you to use a larger number of colors in your application without interfering with the colors used by other forms (windows) in your program. After calling the RealizePalette function, you need only select the colors with which you want to paint the rectangles and the gradient background effect is created.
This program shows how to draw a gradient background on a form/window in Visual Basic.
Private Declare Function RealizePalette Lib "gdi32"
(ByVal hdc As Long) As Long
Dim RedColor(256) As Integer
Dim GreenColor(256) As Integer
Dim BlueColor(256) As Integer
Private Sub Form_Load()
For I = 1 To 256
RedColor(I) = 1
GreenColor(I) = 1
BlueColor(I) = I
Next I
End Sub
Private Sub Command1_Click()
dummy = RealizePalette(Form1.hdc)
Form1.Scale (0, 0)-(256, 1)
For I = 0 To 255
Form1.Line (I, 0)-(I + 1, 1), RGB(RedColor(I + 1), _
GreenColor(I + 1), BlueColor(I + 1)), BF
Form1.ForeColor = RGB(RedColor(I + 1), GreenColor(I + 1), _
BlueColor(I + 1))
Next I
End Sub
Private Sub Command2_Click()
dummy = RealizePalette(Form1.hdc)
Form1.Scale (0, 0)-(1, 256)
For I = 0 To 255
Form1.Line (0, I)-(1, I + 1), RGB(RedColor(I + 1), _
GreenColor(I + 1), BlueColor(I + 1)), BF
Form1.ForeColor = RGB(RedColor(I + 1), GreenColor(I + 1), _
BlueColor(I + 1))
Next I
End Sub
Run the example program by pressing When you click the first Command Button control, the program draws the black-to-blue gradient background horizontally across the form. Clicking the second Command Button control instructs the program to draw the gradient background vertically down the form.
"Color Palettes." (MSDN Library, SDK Documentation, Platform SDK)
Knowledge Base Q128637. "How to Draw a Gradient Background."
"RealizePalette QuickInfo Overview Group." (MSDN Library, SDK Documentation, Platform SDK)