home account info subscribe login search FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Advanced Visual Basic Techniques
(Publisher: John Wiley & Sons, Inc.)
Author(s): Rod Stephens
ISBN: 0471188816
Publication Date: 06/01/97

Search this book:
 
Previous Table of Contents Next


Table 17.1 lists the decimal values of some useful colors. These colors are standard system colors so they should be available on most computers.

The Web page Colors.HTM in the Ch17 subdirectory displays the colors listed in Table 17.1. It creates a table that displays a sample of each of the colors, together with its name and decimal value. The page uses the BackColor properties of WebLabel controls to display the color samples. As with other Web pages, you will need to change the class ID and CODEBASE values used by this page before you can display it on your system.

Table 17.1 Decimal Representations of Useful Color Values
Color Value
Black 0
Dark red 128
Dark green 32768
Dark yellow 32896
Dark blue 8388608
Dark magenta 8388736
Dark cyan 8421376
Light gray 12632256
Money green 12639424
Sky blue 15780518
Cream 15793151
Medium gray 10789024
Dark gray 8421504
Red 255
Green 65280
Yellow 65535
Blue 16711680
Magenta 16711935
Cyan 16776960
White 16777215

The following code shows the table row entry Colors.HTM used to display the color sky blue. The <TR> and </TR> tags delimit a table row. Within a row the <TD> and </TD> tags delimit the table data entries. Each of the entries is placed in a separate column in the row.

<TR>
<TD>
<OBJECT WIDTH=50 HEIGHT=20
CLASSID=“CLSID:1AC27CA9-9A55-11D0-AA35-0000E8167669”
CODEBASE=“http://beauty/WebLabel/WebLabel.CAB#version=1,0,0,0”>
    <PARAM NAME=“BackColor” VALUE=“15780518”>
</OBJECT>
</TD>
<TD>Sky blue</TD>
<TD>15780518</TD>
</TR>

The HTML code in PickClr.HTM in the Ch17 subdirectory is also useful for selecting colors. It creates a bar gauge control and a label control for each of the colors red, green, and blue. It then creates two labels named ColorSwatch and ColorLabel.

Using the bar gauges, the user can adjust the amount of red, green, and blue that should be combined to form a new color. When the user changes a gauge’s value, a VBScript event handler updates the gauge’s corresponding label to show the amount of the color selected on a 0 to 255 scale. It then calculates the new color value using the specified amounts of red, green, and blue. It sets the BackColor property of the ColorSwatch label to this value so the user can see a sample of the color. It also updates the ColorLabel control’s Caption property so the user can see the color’s decimal value.

The following code shows the portions of PickClr.HTM that deal with the red color component. The code that handles the green and blue colors is very similar.

<HTML>
    :
<!-- Red gauge -->
<OBJECT ID=“RedGauge” WIDTH=200 HEIGHT=18
CLASSID=“CLSID:1AC27B55-9A55-11D0-AA35-0000E8167669”
CODEBASE=“http://beauty/Gauge/Gauge.CAB#version=1,0,0,0”>
    <PARAM NAME=“ForeColor” VALUE=“255”>
    <PARAM NAME=“BackColor” VALUE=“12632256”>
    <PARAM NAME=“Min” VALUE=“0”>
    <PARAM NAME=“Max” VALUE=“255”>
    <PARAM NAME=“Value” VALUE=“128”>
    <PARAM NAME=“Style“ VALUE=”0“>
</OBJECT>

<!-- Red gauge’s label -->
<OBJECT ID=”RedLabel“ WIDTH=50 HEIGHT=18
CLASSID=”CLSID:1AC27CA9-9A55-11D0-AA35-0000E8167669“
CODEBASE=“http://beauty/WebLabel/WebLabel.CAB#version=1,0,0,0”>
    <PARAM NAME=“ForeColor” VALUE=“0”>
</OBJECT>
<BR>
    :
<!-- Create gauges and labels for green and blue similarly -->
    :
<!-- Labels to display the selected color -->
<OBJECT ID=“ColorSwatch” WIDTH=50 HEIGHT=50
CLASSID=“CLSID:1AC27CA9-9A55-11D0-AA35-0000E8167669”
CODEBASE=“http://beauty/WebLabel/WebLabel.CAB#version=1,0,0,0”>
</OBJECT>

<OBJECT ID=“ColorLabel” WIDTH=50 HEIGHT=18
CLASSID=“CLSID:1AC27CA9-9A55-11D0-AA35-0000E8167669”
CODEBASE=“http://beauty/WebLabel/WebLabel.CAB#version=1,0,0,0”>
</OBJECT>
<BR>

<SCRIPT LANGUAGE=“VBScript”>
‘ <!--

‘ Red events
Sub RedGauge_Scroll
    RedLabel.Caption = RedGauge.Value
    ShowColor
End Sub
Sub RedGauge_Change
    RedLabel.Caption = RedGauge.Value
    ShowColor
End Sub

‘ The green and blue events are similar.
   :
‘ Set the initial label values when we load.
Sub Window_OnLoad
    RedGauge_Change
    GreenGauge_Change
    BlueGauge_Change
End Sub

‘ Update the color swatch and label
Sub ShowColor
Dim val

    val = ((BlueGauge.Value * 256) + _
            GreenGauge.Value) * 256 + RedGauge.Value
    ColorLabel.Caption = val
    ColorSwatch.BackColor = val
End Sub

‘ -->
</SCRIPT>
</BODY>
</HTML>

Once again, you need to modify the code to set the correct class IDs and CODEBASE values before you can run this page on your computer.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-1999 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.