Method
RGB
Warning
This item was deprecated in version 2019r2. Please use Color.RGB as a replacement.
Description
Returns a Color based on the red, green, blue, and alpha values specified. You can also specify a color using the Color.HSV or Color.CMY function or the &c color constant, &c constructor to create pictures that support the alpha channel or convert existing pictures to the new format using the code described in HasAlphaChannel.
Usage
result=RGB(red, green, blue, [alpha = 0])
Part |
Type |
Description |
---|---|---|
result |
An object that represents the color based on the red, green, blue, and alpha values. |
|
red |
The amount of red in the color (0-255). |
|
green |
The amount of green in the color (0-255). |
|
blue |
The amount of blue in the color (0-255). |
|
alpha |
The amount of translucency of the color (0 - 255 ). The value of zero is opaque and 255 is transparent. The default is zero (opaque). |
Notes
The RGB function returns a color object based on the amounts of red, green, blue, and transparency passed. These amounts are represented by integers between 0 and 255.
You can also specify a color using the RGB model using the &c literal. With the &c literal, you specify the amounts of red, green, blue, and transparency in hexadecimal rather than decimal.
Transparency
The following example draws sample color patches in a Canvas with varying levels of transparency. With the RGB function, the range is from 0 to 255. Zero is completely opaque and 255 is completely transparent. The code is in the Paint event.
g.ForeColor =Color.RGB(255, 0, 0, 0) ' red color patch, no transparency
g.DrawRect(0, 0, 200, 50)
g.FillRect(0, 0, 200, 50)
g.ForeColor =Color.RGB(0, 0, 0) ' black text
g.DrawString("Translucent = 0", 210, 10)
g.ForeColor =Color.RGB(255, 0, 0, 77) ' transparency = .3
g.FillRect(0, 70, 200, 50)
g.ForeColor =Color.RGB(0, 0, 0, 0)
g.DrawString("Translucent = 30%", 210, 80)
g.ForeColor =Color.RGB(255, 0, 0, 127) ' transparency = .5
g.FillRect(0, 140, 200, 50)
g.ForeColor =Color.RGB(0, 0, 0)
g.DrawString("Translucent = 50%", 210, 150)
g.ForeColor =Color.RGB(255, 0, 0, 179) ' transparency = .7
g.FillRect(0, 210, 200, 50)
g.ForeColor =Color.RGB(0, 0, 0)
g.DrawString("Translucent = 70%", 210, 220)
g.ForeColor =Color.RGB(255, 0, 0, 229) ' transparency = .9
g.FillRect(0, 280, 200, 50)
g.ForeColor =Color.RGB(0, 0, 0)
g.DrawString("Translucent = 90%", 210, 290)
The result is shown here.
Sample code
This example uses the RGB function to assign various colors and levels of transparency to the ForeColor property of a Canvas control. The code is in the Paint event.
g.ForeColor =Color.RGB(0, 0, 0, 0) ' set to black
g.ForeColor =Color.RGB(255, 0, 0, 0) ' set to red
g.ForeColor =Color.RGB(255, 255, 255, 0) ' set to white
This example draws three red rectangles with varying levels of transparency. The code is in the Paint event of a Canvas or a Window.
g.ForeColor =Color.RGB(255, 0, 0, 0)
g.DrawRect(0, 0, 200, 50)
g.FillRect(0, 0, 200, 50)
g.ForeColor =Color.RGB(0, 0, 0)
g.DrawString("Translucent = 0", 210, 10)
g.ForeColor =Color.RGB(255, 0, 0, 100) ' transparency = 100
g.FillRect(0, 70, 200, 50)
g.ForeColor =Color.RGB(0, 0, 0, 0)
g.DrawString("Translucent = 100", 210, 80)
g.ForeColor =Color.RGB(255, 0, 0, 200) ' transparency = 200
g.FillRect(0, 140, 200, 50)
g.ForeColor =Color.RGB(0, 0, 0, 0)
g.DrawString("Translucent = 200", 210, 150)
Compatibility
All project types on all supported operating systems.
See also
Color data type; Color.CMY, Color.HSV, Color.SelectedFromDialog functions; &c literal.