Color
From Xojo Documentation
The data type for storing color values with an optional alpha component. The default value of a Color is &c000000 (black).
Constants | ||||||||||||||||
|
Properties | ||||||||||
|
Shared Methods | ||||||||||||||||
|
Notes
Colors are often used to assign colors to properties of type Color. Use the RGB, HSV, or CMY functions to assign a color to an object or use the format:
In the above, RR is the RGB value of Red in hexadecimal, GG is the value Green in hexadecimal, and BB is the value of Blue in hexadecimal. You can right-click in the Code Editor and select Insert Color to choose a color using the color picker, which will insert the hexadecimal value at the cursor position in the editor.
Desktop, Web and Console projects can also use the CMY function to set the color using cyan, magenta and yellow elements. The CMY function is not available for iOS projects.
You can use the VarType function to determine whether a property or a variable is a Color. If it is, VarType returns 16.
Color Values to/from Hex Strings
Desktop, Web and Console projects can use the Str global function to get the hexadecimal RGB value of a Color:To convert a hexadecimal color value back to a Color, you first have to convert it to a 32-bit Integer (Int32 or UInt32) and then cast it to a Color like this:Var intColor As Int32 = hexColor.Val // Can also use UInt32
Var c2 As Color = Color(intColor)
Alpha Channel Support
The Color type has a read-only "Alpha" property. The alpha channel is the transparency of the color represented as an integer between 0 (opaque) and 255 (transparent).
The Color literal syntax can optionally have two more hexadecimal digits at the end representing the alpha channel (for example, "&cFF00007F"). If the color literal has only 3 channels of information, the alpha component defaults to 0.
The RGB, HSV, and CMY functions also have an optional integer parameter that specifies the alpha channel for the Color.
Sample Code
The following example uses the RGB model to set the DrawingColor property of a Canvas control and draw a square using the current DrawingColor. The code is placed in the Canvas control's Paint event.
g.DrawRectangle(0, 0, 50, 50)
The following example (in a Canvas Paint event) assigns a color directly using the RGB color model. The RGB values must be specified in hexadecimal:
g.DrawRectangle(0, 0, 50, 50)
The following example uses the CMY model to set the fillcolor of a Rectangle control, r.
The following example inverts the fillcolor:
c=Color.RGB(255 - r.FillColor.Red, 255 - r.FillColor.Green, 255 - r.FillColor.Blue)
r.FillColor = c
See Also
Str, Val, VarType functions; &c literal; ColorGroup class