Color.FromArgb 方法

定義

從四個 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)

從四個 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)

從指定的 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)

從指定的 Color 結構 (但是使用新指定的 Alpha 值) 建立 Color 結構。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)

從 32 位元的 ARGB 值建立 Color 結構。Creates a Color structure from a 32-bit ARGB value.

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

Alpha 元件。The alpha component. 有效值為 0 到 255 之間。Valid values are 0 through 255.

red
Int32

紅色元件。The red component. 有效值為 0 到 255 之間。Valid values are 0 through 255.

green
Int32

綠色元件。The green component. 有效值為 0 到 255 之間。Valid values are 0 through 255.

blue
Int32

藍色元件。The blue component. 有效值為 0 到 255 之間。Valid values are 0 through 255.

傳回

Color

這個方法建立的 ColorThe Color that this method creates.

例外狀況

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

範例

下列程式碼範例是設計用來搭配 Windows Forms 使用,它需要 PaintEventArgs ePaint 事件處理常式的參數。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)

從指定的 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

Color 的紅色元件值。The red component value for the new Color. 有效值為 0 到 255 之間。Valid values are 0 through 255.

green
Int32

Color 的綠色元件值。The green component value for the new Color. 有效值為 0 到 255 之間。Valid values are 0 through 255.

blue
Int32

Color 的藍色元件值。The blue component value for the new Color. 有效值為 0 到 255 之間。Valid values are 0 through 255.

傳回

Color

這個方法建立的 ColorThe Color that this method creates.

例外狀況

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

範例

下列程式碼範例是設計用來搭配 Windows Forms 使用,它需要 PaintEventArgs ePaint 事件處理常式的參數。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)

從指定的 Color 結構 (但是使用新指定的 Alpha 值) 建立 Color 結構。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

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

baseColor
Color

Color,用於建立新的 ColorThe Color from which to create the new Color.

傳回

Color

這個方法建立的 ColorThe Color that this method creates.

例外狀況

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

範例

下列程式碼範例是設計用來搭配 Windows Forms 使用,它需要 PaintEventArgs ePaint 事件處理常式的參數。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)

從 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

數值,指定 32 位元 ARGB 值。A value specifying the 32-bit ARGB value.

傳回

Color

這個方法建立的 Color 結構。The Color structure that this method creates.

範例

下列程式碼範例是設計用來搭配 Windows Forms 使用,它需要 PaintEventArgs ePaint 事件處理常式的參數。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. 最重要的位元組 (MSB) (以 AA 表示)是 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.

適用於