&c

From Xojo Documentation

Literal

Used to represent a color literal.

Usage

&cRRGGBBAA

Part Type Description
RR String The amount of Red in the color, in hexadecimal. The range is from 00 to FF.
GG String The amount of Green in the color, in hexadecimal. The range is from 00 to FF.
BB String The amount of Blue in the color, in hexadecimal. The range is from 00 to FF.
AA String The amount of transparency (alpha channel) in the color, in hexadecimal. The range is from 00 (opaque) to FF (fully transparent).

Notes

&c is an alternative to the RGB function for specifying a Color using the RGB model. It provides the same functionality as the RGB function, except that you specify the amount of each primary color and the level of transparency in hexadecimal (00-FF) rather than decimal (0-255).

In the Code Editor, the parameters RR, GG, and BB appear in the color that they represent. The amount of transparency appears in the default color for text in the Code Editor. A color can also be specified using the HSV and CMY models.

To create a picture that supports the alpha channel, use the new form of the Picture constructor to create pictures or convert existing pictures to the new format using the code described in HasAlphaChannel.

Sample Code

Dim red As Color = &cFF000000
Dim blue As Color = &c0000FF10 // mostly transparent

This example fills a Canvas with a 50% transparent color:

g.ForeColor = &cff00007f
g.FillRect(0,0,me.width,me.height)

Transparency

The following example draws sample color patches in a Canvas. The code is in the Paint event.

g.ForeColor = &cff000000 // red color patch, no transparency
g.Drawrect(0, 0, 200, 50)
g.FillRect(0, 0, 200, 50)
g.ForeColor = &c000000 // black text
g.DrawString("Translucent = 0", 210, 10)

g.ForeColor = &cff00004d // transparency = 30%
g.FillRect(0, 70, 200, 50)
g.ForeColor = &c000000
g.DrawString("Translucent = 30%", 210, 80)

g.ForeColor = &cff00007f // transparency = 50%
g.FillRect(0, 140, 200, 50)
g.ForeColor = &c000000
g.DrawString("Translucent = 50%", 210, 150)

g.ForeColor = &cff000083 // transparency = 70%
g.FillRect(0, 210, 200, 50)
g.ForeColor = &c000000
g.DrawString("Translucent = 70%", 210, 220)

g.ForeColor = &cff0000e5 // transparency = 90%
g.FillRect(0, 280, 200, 50)
g.ForeColor = &c000000
g.DrawString("Translucent = 90%", 210, 290)

The result is shown here.

Sample red color patches illustrating transparency.

Color Picker Example

The following example allows the user to select a color that will be used as the fillcolor in a Rectangle control.

Dim c As Color
Dim b As Boolean
c = &cFFFFFF // set the default color shown in color picker (white in this case)
b = SelectColor(c, "Select a Color")
Rectangle1.FillColor = c

See Also

CMY, HSV, RGB functions; Color, Graphics, Picture classes.