Color.FromArgb Method (Int32)
.NET Framework 2.0
Creates a Color structure from a 32-bit ARGB value.
Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)
Assembly: System.Drawing (in system.drawing.dll)
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.
void FromArgb4( PaintEventArgs^ e ) { Graphics^ g = e->Graphics; // Transparent red, green, and blue brushes. SolidBrush^ trnsRedBrush = gcnew SolidBrush( Color::FromArgb( 0x78FF0000 ) ); SolidBrush^ trnsGreenBrush = gcnew SolidBrush( Color::FromArgb( 0x7800FF00 ) ); SolidBrush^ trnsBlueBrush = gcnew SolidBrush( Color::FromArgb( 0x780000FF ) ); // 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 circles. float triBase = 100; float triHeight = (float)Math::Sqrt( 3 * (triBase * triBase) / 4 ); // coordinates of first circle's bounding rectangle. float x1 = 40; float y1 = 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 ); }
public void FromArgb4(PaintEventArgs e)
{
Graphics g = e.get_Graphics();
// Transparent red, green, and blue brushes.
SolidBrush trnsRedBrush = new SolidBrush(Color.FromArgb(0x78FF0000));
SolidBrush trnsGreenBrush = new SolidBrush(Color.FromArgb(0x7800FF00));
SolidBrush trnsBlueBrush = new SolidBrush(Color.FromArgb(0x780000FF));
// 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 circles.
float triBase = 100;
float triHeight = (float)(Math.sqrt((3 * (triBase * triBase) / 4)));
// coordinates of first circle's bounding rectangle.
float x1 = 40;
float y1 = 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);
} //FromArgb4
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.Community Additions
ADD
Show: