Color.FromArgb Method (Int32)
Creates a Color structure from a 32-bit ARGB value.
Assembly: System.Drawing (in System.Drawing.dll)
Parameters
- argb
-
Type:
System.Int32
A value specifying the 32-bit ARGB value.
The byte-ordering of the 32-bit ARGB value is AARRGGBB. The most significant byte (MSB), represented by AA, is the alpha component value. The second, third, and fourth bytes, represented by RR, GG, and BB, respectively, are the color components red, green, and blue, respectively.
The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. The code performs the following actions:
Creates three brushes, each a different color. Each Color structure that is used to create a brush is created from a 32-bit ARGB value.
Uses an imaginary triangle to position three circles.
Paints three overlapping circles, each centered on one vertex of the triangle, using a different brush for each circle.
Public Sub FromArgb4(ByVal e As PaintEventArgs) Dim g As Graphics = e.Graphics ' Transparent red, green, and blue brushes. Dim trnsRedBrush As New SolidBrush(Color.FromArgb(&H78FF0000)) Dim trnsGreenBrush As New SolidBrush(Color.FromArgb(&H7800FF00)) Dim trnsBlueBrush As New SolidBrush(Color.FromArgb(&H780000FF)) ' Base and height of the triangle that is used to position the ' circles. Each vertex of the triangle is at the center of one of ' the 3 circles. The base is equal to the diameter of the circle. Dim triBase As Single = 100 Dim triHeight As Single = CSng(Math.Sqrt((3 * (triBase * _ triBase) / 4))) ' Coordinates of first circle 's bounding rectangle. Dim x1 As Single = 40 Dim y1 As Single = 40 ' Fill 3 over-lapping circles. Each circle is a different color. g.FillEllipse(trnsRedBrush, x1, y1, 2 * triHeight, 2 * triHeight) g.FillEllipse(trnsGreenBrush, x1 + triBase / 2, y1 + triHeight, _ 2 * triHeight, 2 * triHeight) g.FillEllipse(trnsBlueBrush, x1 + triBase, y1, 2 * triHeight, _ 2 * triHeight) End Sub
Available since 1.1