Color.FromArgb Color.FromArgb Color.FromArgb Color.FromArgb Method

定义

基于四个 8 位 ARGB 组件(alpha、红色、绿色和蓝色)值创建 Color 结构。Creates a Color structure from the four 8-bit ARGB components (alpha, red, green, and blue) values.

重载

FromArgb(Int32, Int32, Int32, Int32) FromArgb(Int32, Int32, Int32, Int32) FromArgb(Int32, Int32, Int32, Int32) FromArgb(Int32, Int32, Int32, Int32)

基于四个 ARGB 组件(alpha、红色、绿色和蓝色)值创建 Color 结构。Creates a Color structure from the four ARGB component (alpha, red, green, and blue) values. 尽管此方法允许为每个组件传递 32 位值,但每个组件的值仅限于 8 位。Although this method allows a 32-bit value to be passed for each component, the value of each component is limited to 8 bits.

FromArgb(Int32, Int32, Int32) FromArgb(Int32, Int32, Int32) FromArgb(Int32, Int32, Int32) FromArgb(Int32, Int32, Int32)

基于指定的 8 位颜色值(红色、绿色和蓝色)创建 Color 结构。Creates a Color structure from the specified 8-bit color values (red, green, and blue). 隐式的 alpha 值为 255(完全不透明)。The alpha value is implicitly 255 (fully opaque). 尽管此方法允许为每个颜色组件传递 32 位值,但每个组件的值仅限于 8 位。Although this method allows a 32-bit value to be passed for each color component, the value of each component is limited to 8 bits.

FromArgb(Int32, Color) FromArgb(Int32, Color) FromArgb(Int32, Color) FromArgb(Int32, Color)

从指定的 Color 结构创建 Color 结构,但要使用新指定的 alpha 值。Creates a Color structure from the specified Color structure, but with the new specified alpha value. 尽管此方法允许为 alpha 值传递 32 位值,但该值仅限于 8 位。Although this method allows a 32-bit value to be passed for the alpha value, the value is limited to 8 bits.

FromArgb(Int32) FromArgb(Int32) FromArgb(Int32) FromArgb(Int32)

基于一个 32 位 ARGB 值创建 Color 结构。Creates a Color structure from a 32-bit ARGB value.

FromArgb(Int32, Int32, Int32, Int32) FromArgb(Int32, Int32, Int32, Int32) FromArgb(Int32, Int32, Int32, Int32) FromArgb(Int32, Int32, Int32, Int32)

基于四个 ARGB 组件(alpha、红色、绿色和蓝色)值创建 Color 结构。Creates a Color structure from the four ARGB component (alpha, red, green, and blue) values. 尽管此方法允许为每个组件传递 32 位值,但每个组件的值仅限于 8 位。Although this method allows a 32-bit value to be passed for each component, the value of each component is limited to 8 bits.

public:
 static System::Drawing::Color FromArgb(int alpha, int red, int green, int blue);
public static System.Drawing.Color FromArgb (int alpha, int red, int green, int blue);
static member FromArgb : int * int * int * int -> System.Drawing.Color
Public Shared Function FromArgb (alpha As Integer, red As Integer, green As Integer, blue As Integer) As Color

参数

alpha
Int32 Int32 Int32 Int32

Alpha 组件。The alpha component. 有效值为 0 到 255。Valid values are 0 through 255.

red
Int32 Int32 Int32 Int32

红色组件。The red component. 有效值为 0 到 255。Valid values are 0 through 255.

green
Int32 Int32 Int32 Int32

绿色组件。The green component. 有效值为 0 到 255。Valid values are 0 through 255.

blue
Int32 Int32 Int32 Int32

蓝色组件。The blue component. 有效值为 0 到 255。Valid values are 0 through 255.

返回

此方法创建的 ColorThe Color that this method creates.

异常

alpharedgreenblue 小于 0 或大于 255。alpha, red, green, or blue is less than 0 or greater than 255.

示例

下面的代码示例设计为使用 Windows 窗体,并且它需要PaintEventArgs e,这是一个参数的Paint事件处理程序。The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler. 该代码执行下列操作:The code performs the following actions:

  • 创建三个画笔、 每个不同的颜色。Creates three brushes, each a different color. 每个Color从四个组件值 (alpha、 红色、 绿色、 蓝色) 创建用于创建画笔的结构。Each Color structure that is used to create a brush is created from four component values (alpha, red, green, blue).

  • 使用虚构的三角形来定位三个圆圈。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 FromArgb1( PaintEventArgs^ e )
{
   Graphics^ g = e->Graphics;

   // Transparent red, green, and blue brushes.
   SolidBrush^ trnsRedBrush = gcnew SolidBrush( Color::FromArgb( 120, 255, 0, 0 ) );
   SolidBrush^ trnsGreenBrush = gcnew SolidBrush( Color::FromArgb( 120, 0, 255, 0 ) );
   SolidBrush^ trnsBlueBrush = gcnew SolidBrush( Color::FromArgb( 120, 0, 0, 255 ) );

   // 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 FromArgb1(PaintEventArgs e)
{
    Graphics     g = e.Graphics;
             
    // Transparent red, green, and blue brushes.
    SolidBrush trnsRedBrush = new SolidBrush(Color.FromArgb(120, 255, 0, 0));
    SolidBrush trnsGreenBrush = new SolidBrush(Color.FromArgb(120, 0, 255, 0));
    SolidBrush trnsBlueBrush = new SolidBrush(Color.FromArgb(120, 0, 0, 255));
             
    // 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 Sub FromArgb1(ByVal e As PaintEventArgs)
    Dim g As Graphics = e.Graphics

    ' Transparent red, green, and blue brushes.
    Dim trnsRedBrush As New SolidBrush(Color.FromArgb(120, 255, 0, 0))
    Dim trnsGreenBrush As New SolidBrush(Color.FromArgb(120, 0, _
    255, 0))
    Dim trnsBlueBrush As New SolidBrush(Color.FromArgb(120, 0, 0, 255))

    ' 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

注解

若要创建不透明的颜色,请设置alpha到 255 之间。To create an opaque color, set alpha to 255. 若要创建半透明的颜色,请设置alpha为从 1 到 254 的任何值。To create a semitransparent color, set alpha to any value from 1 through 254.

FromArgb(Int32, Int32, Int32) FromArgb(Int32, Int32, Int32) FromArgb(Int32, Int32, Int32) FromArgb(Int32, Int32, Int32)

基于指定的 8 位颜色值(红色、绿色和蓝色)创建 Color 结构。Creates a Color structure from the specified 8-bit color values (red, green, and blue). 隐式的 alpha 值为 255(完全不透明)。The alpha value is implicitly 255 (fully opaque). 尽管此方法允许为每个颜色组件传递 32 位值,但每个组件的值仅限于 8 位。Although this method allows a 32-bit value to be passed for each color component, the value of each component is limited to 8 bits.

public:
 static System::Drawing::Color FromArgb(int red, int green, int blue);
public static System.Drawing.Color FromArgb (int red, int green, int blue);
static member FromArgb : int * int * int -> System.Drawing.Color
Public Shared Function FromArgb (red As Integer, green As Integer, blue As Integer) As Color

参数

red
Int32 Int32 Int32 Int32

Color 的红色组件值。The red component value for the new Color. 有效值为 0 到 255。Valid values are 0 through 255.

green
Int32 Int32 Int32 Int32

Color 的绿色组件值。The green component value for the new Color. 有效值为 0 到 255。Valid values are 0 through 255.

blue
Int32 Int32 Int32 Int32

Color 的蓝色组件值。The blue component value for the new Color. 有效值为 0 到 255。Valid values are 0 through 255.

返回

此方法创建的 ColorThe Color that this method creates.

异常

redgreenblue 小于 0 或大于 255。red, green, or blue is less than 0 or greater than 255.

示例

下面的代码示例设计为使用 Windows 窗体,并且它需要PaintEventArgs e,这是一个参数的Paint事件处理程序。The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler. 该代码执行下列操作:The code performs the following actions:

  1. 创建Color从三个颜色组件值 (红色、 绿色、 蓝色) 的结构。Creates Color structures from the three color component values (red, green, blue). 三个Color创建结构,一个用于每种基本色。Three Color structures are created, one for each primary color.

  2. 循环访问一系列更改一种颜色的 alpha 值的 alpha 值。Iterates through a range of alpha values, changing the alpha value of a color.

  3. 每次迭代过程将画笔的颜色设置为修改后的颜色和绘制一个矩形,以显示该颜色。During each iteration, sets the color of a brush to the modified color and paints a rectangle to show the color.

  4. 针对每种基本色重复步骤 2 和 3。Repeats steps 2 and 3 for each primary color.

Alpha 值决不会是完全不透明和矩形重叠,因此,获取颜色组合效果。The alpha value is never fully opaque and the rectangles overlap so you get color-combination effects.

void FromArgb2( PaintEventArgs^ e )
{
   Graphics^ g = e->Graphics;

   // Opaque colors (alpha value defaults to 255 -- max value).
   Color red = Color::FromArgb( 255, 0, 0 );
   Color green = Color::FromArgb( 0, 255, 0 );
   Color blue = Color::FromArgb( 0, 0, 255 );

   // Solid brush initialized to red.
   SolidBrush^ myBrush = gcnew SolidBrush( red );
   int alpha;

   // x coordinate of first red rectangle
   int x = 50;

   // y coordinate of first red rectangle
   int y = 50;

   // Fill rectangles with red, varying the alpha value from 25 to 250.
   for ( alpha = 25; alpha <= 250; alpha += 25 )
   {
      myBrush->Color = Color::FromArgb( alpha, red );
      g->FillRectangle( myBrush, x, y, 50, 100 );
      g->FillRectangle( myBrush, x, y + 250, 50, 50 );
      x += 50;
   }
   x = 50;

   // y coordinate of first green rectangle.
   y += 50;

   // Fill rectangles with green, varying the alpha value from 25 to 250.
   for ( alpha = 25; alpha <= 250; alpha += 25 )
   {
      myBrush->Color = Color::FromArgb( alpha, green );
      g->FillRectangle( myBrush, x, y, 50, 150 );
      x += 50;
   }
   x = 50;

   // y coordinate of first blue rectangle.
   y += 100;

   // Fill rectangles with blue, varying the alpha value from 25 to 250.
   for ( alpha = 25; alpha <= 250; alpha += 25 )
   {
      myBrush->Color = Color::FromArgb( alpha, blue );
      g->FillRectangle( myBrush, x, y, 50, 150 );
      x += 50;
   }
}
public void FromArgb2(PaintEventArgs e)
{
    Graphics     g = e.Graphics;
             
    // Opaque colors (alpha value defaults to 255 -- max value).
    Color red = Color.FromArgb(255, 0, 0);
    Color green = Color.FromArgb(0, 255, 0);
    Color blue = Color.FromArgb(0, 0, 255);
             
    // Solid brush initialized to red.
    SolidBrush  myBrush = new SolidBrush(red);
    int alpha;

    // x coordinate of first red rectangle
    int x = 50;         
    
    // y coordinate of first red rectangle
    int y = 50;         
                   
    // Fill rectangles with red, varying the alpha value from 25 to 250.
    for (alpha = 25; alpha <= 250; alpha += 25)
    {
        myBrush.Color = Color.FromArgb(alpha, red);
        g.FillRectangle(myBrush, x, y, 50, 100);
        g.FillRectangle(myBrush, x, y + 250, 50, 50);
        x += 50;
    }
    // x coordinate of first green rectangle.
    x = 50;             
    
    // y coordinate of first green rectangle.
    y += 50;            
                      
    // Fill rectangles with green, varying the alpha value from 25 to 250.
    for (alpha = 25; alpha <= 250; alpha += 25)
    {
        myBrush.Color = Color.FromArgb(alpha, green);
        g.FillRectangle(myBrush, x, y, 50, 150);
        x += 50;
    }
    // x coordinate of first blue rectangle.
    x = 50;             
    
    // y coordinate of first blue rectangle.
    y += 100;           
             
    // Fill rectangles with blue, varying the alpha value from 25 to 250.
    for (alpha = 25; alpha <= 250; alpha += 25)
    {
        myBrush.Color = Color.FromArgb(alpha, blue);
        g.FillRectangle(myBrush, x, y, 50, 150);
        x += 50;
    }
}
Public Sub FromArgb2(ByVal e As PaintEventArgs)
    Dim g As Graphics = e.Graphics

    ' Opaque colors (alpha value defaults to 255 -- max value).
    Dim red As Color = Color.FromArgb(255, 0, 0)
    Dim green As Color = Color.FromArgb(0, 255, 0)
    Dim blue As Color = Color.FromArgb(0, 0, 255)

    ' Solid brush initialized to red.
    Dim myBrush As New SolidBrush(red)
    Dim alpha As Integer

    ' x coordinate of first red rectangle.
    Dim x As Integer = 50

    ' y coordinate of first red rectangle.
    Dim y As Integer = 50

    ' Fill rectangles with red, varying the alpha value from 25 to 250.
    For alpha = 25 To 250 Step 25
        myBrush.Color = Color.FromArgb(alpha, red)
        g.FillRectangle(myBrush, x, y, 50, 100)
        g.FillRectangle(myBrush, x, y + 250, 50, 50)
        x += 50
    Next alpha

    ' x coordinate of first green rectangle.
    x = 50

    ' y coordinate of first green rectangle.
    y += 50


    ' Fill rectangles with green, varying alpha value from 25 to 250.
    For alpha = 25 To 250 Step 25
        myBrush.Color = Color.FromArgb(alpha, green)
        g.FillRectangle(myBrush, x, y, 50, 150)
        x += 50
    Next alpha

    ' x coordinate of first blue rectangle.
    x = 50

    ' y coordinate of first blue rectangle.
    y += 100

    ' Fill rectangles with blue, varying alpha value from 25 to 250.
    For alpha = 25 To 250 Step 25
        myBrush.Color = Color.FromArgb(alpha, blue)
        g.FillRectangle(myBrush, x, y, 50, 150)
        x += 50
    Next alpha
End Sub

FromArgb(Int32, Color) FromArgb(Int32, Color) FromArgb(Int32, Color) FromArgb(Int32, Color)

从指定的 Color 结构创建 Color 结构,但要使用新指定的 alpha 值。Creates a Color structure from the specified Color structure, but with the new specified alpha value. 尽管此方法允许为 alpha 值传递 32 位值,但该值仅限于 8 位。Although this method allows a 32-bit value to be passed for the alpha value, the value is limited to 8 bits.

public:
 static System::Drawing::Color FromArgb(int alpha, System::Drawing::Color baseColor);
public static System.Drawing.Color FromArgb (int alpha, System.Drawing.Color baseColor);
static member FromArgb : int * System.Drawing.Color -> System.Drawing.Color
Public Shared Function FromArgb (alpha As Integer, baseColor As Color) As Color

参数

alpha
Int32 Int32 Int32 Int32

Color 的 alpha 值。The alpha value for the new Color. 有效值为 0 到 255。Valid values are 0 through 255.

baseColor
Color Color Color Color

从中创建新 ColorColorThe Color from which to create the new Color.

返回

此方法创建的 ColorThe Color that this method creates.

异常

alpha 小于 0 或大于 255。alpha is less than 0 or greater than 255.

示例

下面的代码示例设计为使用 Windows 窗体,并且它需要PaintEventArgs e,这是一个参数的Paint事件处理程序。The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler. 该代码执行下列操作:The code performs the following actions:

  1. 创建Color从三个颜色组件值 (红色、 绿色、 蓝色) 的结构。Creates Color structures from the three color component values (red, green, blue). 三个Color创建结构,一个用于每种基本色。Three Color structures are created, one for each primary color.

  2. 循环访问一系列更改一种颜色的 alpha 值的 alpha 值。Iterates through a range of alpha values, changing the alpha value of a color.

  3. 每次迭代过程将画笔的颜色设置为修改后的颜色和绘制一个矩形,以显示该颜色。During each iteration, sets the color of a brush to the modified color and paints a rectangle to show the color.

  4. 针对每种基本色重复步骤 2 和 3。Repeats steps 2 and 3 for each primary color.

Alpha 值决不会是完全不透明和矩形重叠,因此,获取颜色组合效果。The alpha value is never fully opaque and the rectangles overlap so you get color-combination effects.

void FromArgb3( PaintEventArgs^ e )
{
   Graphics^ g = e->Graphics;

   // Opaque colors (alpha value defaults to 255 -- max value).
   Color red = Color::FromArgb( 255, 0, 0 );
   Color green = Color::FromArgb( 0, 255, 0 );
   Color blue = Color::FromArgb( 0, 0, 255 );

   // Solid brush initialized to red.
   SolidBrush^ myBrush = gcnew SolidBrush( red );
   int alpha;

   // x coordinate of first red rectangle
   int x = 50;

   // y coordinate of first red rectangle
   int y = 50;

   // Fill rectangles with red, varying the alpha value from 25 to 250.
   for ( alpha = 25; alpha <= 250; alpha += 25 )
   {
      myBrush->Color = Color::FromArgb( alpha, red );
      g->FillRectangle( myBrush, x, y, 50, 100 );
      g->FillRectangle( myBrush, x, y + 250, 50, 50 );
      x += 50;
   }
   x = 50;

   // y coordinate of first green rectangle
   y += 50;

   // Fill rectangles with green, varying the alpha value from 25 to 250.
   for ( alpha = 25; alpha <= 250; alpha += 25 )
   {
      myBrush->Color = Color::FromArgb( alpha, green );
      g->FillRectangle( myBrush, x, y, 50, 150 );
      x += 50;
   }
   x = 50;

   // y coordinate of first blue rectangle
   y += 100;

   // Fill rectangles with blue, varying the alpha value from 25 to 250.
   for ( alpha = 25; alpha <= 250; alpha += 25 )
   {
      myBrush->Color = Color::FromArgb( alpha, blue );
      g->FillRectangle( myBrush, x, y, 50, 150 );
      x += 50;
   }
}
public void FromArgb3(PaintEventArgs e)
{
    Graphics     g = e.Graphics;
             
    // Opaque colors (alpha value defaults to 255 -- max value).
    Color red = Color.FromArgb(255, 0, 0);
    Color green = Color.FromArgb(0, 255, 0);
    Color blue = Color.FromArgb(0, 0, 255);
             
    // Solid brush initialized to red.
    SolidBrush  myBrush = new SolidBrush(red);
    int alpha;
    
    // x coordinate of first red rectangle
    int x = 50;         
    
    // y coordinate of first red rectangle
    int y = 50;         
    
    // Fill rectangles with red, varying the alpha value from 25 to 250.
    for (alpha = 25; alpha <= 250; alpha += 25)
    {
        myBrush.Color = Color.FromArgb(alpha, red);
        g.FillRectangle(myBrush, x, y, 50, 100);
        g.FillRectangle(myBrush, x, y + 250, 50, 50);
        x += 50;
    }
    // x coordinate of first green rectangle
    x = 50;             
    
    // y coordinate of first green rectangle
    y += 50;            
    
    // Fill rectangles with green, varying the alpha value from 25 to 250.
    for (alpha = 25; alpha <= 250; alpha += 25)
    {
        myBrush.Color = Color.FromArgb(alpha, green);
        g.FillRectangle(myBrush, x, y, 50, 150);
        x += 50;
    }
    // x coordinate of first blue rectangle.
    x = 50; 
    
     // y coordinate of first blue rectangle
    y += 100;           
   
             
    // Fill rectangles with blue, varying the alpha value from 25 to 250.
    for (alpha = 25; alpha <= 250; alpha += 25)
    {
        myBrush.Color = Color.FromArgb(alpha, blue);
        g.FillRectangle(myBrush, x, y, 50, 150);
        x += 50;
    }
}
Public Sub FromArgb3(ByVal e As PaintEventArgs)
    Dim g As Graphics = e.Graphics

    ' Opaque colors (alpha value defaults to 255 -- max value).
    Dim red As Color = Color.FromArgb(255, 0, 0)
    Dim green As Color = Color.FromArgb(0, 255, 0)
    Dim blue As Color = Color.FromArgb(0, 0, 255)

    ' Solid brush initialized to red.
    Dim myBrush As New SolidBrush(red)
    Dim alpha As Integer

    ' x coordinate of first red rectangle.
    Dim x As Integer = 50

    ' y coordinate of first red rectangle.
    Dim y As Integer = 50

    ' Fill rectangles with red, varying the alpha value from 25 to 250.
    For alpha = 25 To 250 Step 25
        myBrush.Color = Color.FromArgb(alpha, red)
        g.FillRectangle(myBrush, x, y, 50, 100)
        g.FillRectangle(myBrush, x, y + 250, 50, 50)
        x += 50
    Next alpha

    ' x coordinate of first green rectangle.
    x = 50

    ' y coordinate of first green rectangle.
    y += 50

    ' Fill rectangles with green, varying alpha value from 25 to 250.
    For alpha = 25 To 250 Step 25
        myBrush.Color = Color.FromArgb(alpha, green)
        g.FillRectangle(myBrush, x, y, 50, 150)
        x += 50
    Next alpha

    ' x coordinate of first blue rectangle.
    x = 50

    ' y coordinate of first blue rectangle.
    y += 100

    ' Fill rectangles with blue, varying alpha value from 25 to 250.
    For alpha = 25 To 250 Step 25
        myBrush.Color = Color.FromArgb(alpha, blue)
        g.FillRectangle(myBrush, x, y, 50, 150)
        x += 50
    Next alpha
End Sub

注解

若要创建不透明的颜色,请设置alpha到 255 之间。To create an opaque color, set alpha to 255. 若要创建半透明的颜色,请设置alpha为从 1 到 254 的任何值。To create a semitransparent color, set alpha to any value from 1 through 254.

FromArgb(Int32) FromArgb(Int32) FromArgb(Int32) FromArgb(Int32)

基于一个 32 位 ARGB 值创建 Color 结构。Creates a Color structure from a 32-bit ARGB value.

public:
 static System::Drawing::Color FromArgb(int argb);
public static System.Drawing.Color FromArgb (int argb);
static member FromArgb : int -> System.Drawing.Color
Public Shared Function FromArgb (argb As Integer) As Color

参数

argb
Int32 Int32 Int32 Int32

用于指定 32 位 ARGB 值的值。A value specifying the 32-bit ARGB value.

返回

此方法创建的 Color 结构。The Color structure that this method creates.

示例

下面的代码示例设计为使用 Windows 窗体,并且它需要PaintEventArgs e,这是一个参数的Paint事件处理程序。The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler. 该代码执行下列操作:The code performs the following actions:

  • 创建三个画笔、 每个不同的颜色。Creates three brushes, each a different color. 每个Color从 32 位 ARGB 值创建用来创建画笔的结构。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.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);
}
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

注解

字节顺序的 32 位 ARGB 值为 AARRGGBB。The byte-ordering of the 32-bit ARGB value is AARRGGBB. AA,由表示最高有效字节 (MSB) 的 alpha 分量值。The most significant byte (MSB), represented by AA, is the alpha component value. 第二个、 第三和第四个字节,分别表示 RR、 GG 和 BB,分别为颜色组件红色、 绿色和蓝色。The second, third, and fourth bytes, represented by RR, GG, and BB, respectively, are the color components red, green, and blue, respectively.

适用于