Color. ToArgb (): Gets the 32-bit Argb value of this color structure.
Namespace: System. drawing
Assembly: system. Drawing (in System.Drawing.dll)
publicint ToArgb()
Return value
Type: System. Int32
The 32-bit ARGB value of the color.
Note: the byte order of 32-bit ARGB values is AARRGGBB. The most significant byte (MSB) represented by AA is the alpha component value. The second, third and fourth bytes denoted by RR, GG and BB are red, green and blue components, respectively.
Example:
The following code example is designed for a Windows form that requires PaintEventArgse, which is a parameter of the Paint event handler. This code does the following:
Loop through the KnownColor enumeration elements to find all the known colors that have non-zero green components and zero red components and are not system colors. In each iteration, if the KnownColor element matches the condition, it will be saved into the array. Draw a rectangle with a brush. Each rectangle is drawn in a known color that matches the conditions described in the first bullet. The name of KnownColor and its component values are also displayed. This example shows some known colors, their names and their four component values. The ToArgb method is used as a preliminary step to display component values.
public void to argbtostringexample 1(paint eventargs e)
{
Graph g = e. graph;
//Color structure for temporary storage.
Color someColor = color. from argb(0);
//array to store qualified KnownColor values.
known color[]color matches = new known color[ 167];
//Number of matches found.
int count = 0;
//Iterate through the KnownColor enumeration to find all the corresponding colors.
//has a non-zero green component and a zero red component, and
//is not a system color.
for(known color enum value = 0;
enumValue & lt= KnownColor。 Yellow-green; enumValue++)
{
someColor = Color。 FromKnownColor(enum value);
If (someColor. g! = 0&a certain color. R = = 0 & amp& amp! Some color. IsSystemColor)
color matches[count++]= enum value;
}
solid brush my brush 1 = new solid brush(some color);
Font myFont = new Font("Arial ",9);
int x = 40
int y = 40
//Iterate through the found matches and display them.
//corresponds to the enumerated values in the array. The name that is also displayed.
//Known colors and ARGB components.
for(int I = 0; I < count; i++)
{
//Display color.
someColor = Color。 FromKnownColor(color matches[I]);
myBrush 1。 Color = someColor
g.FillRectangle(myBrush 1,x,y,50,30);
//Displays the KnownColor name and four component values. To display
//component value: use the ToArgb method to get the 32-bit Argb value.
SomeColor, which was created from KnownColor. Then create one.
//Get the color structure from the 32-bit ARGB value and set someColor to.
//This new color structure. Then use the ToString method to convert it to.
//A string.
G. pull the rope (a certain color. ToString()、myFont、Brushes。 Black, x+55, y);
someColor = Color。 FromArgb(someColor。 to argb());
G. pull the rope (a certain color. ToString()、myFont、Brushes。 Black, x+55, y+15);
y+= 40;
}
}