次の方法で共有


Color.FromArgb メソッド (Int32, Int32, Int32, Int32)

4 つの ARGB コンポーネント (アルファ、赤、緑、青) 値から Color 構造体を作成します。このメソッドでは各コンポーネントの 32 ビット値を渡すことができますが、各コンポーネントの値は 8 ビットに限定されます。

Overloads Public Shared Function FromArgb( _
   ByVal alpha As Integer, _   ByVal red As Integer, _   ByVal green As Integer, _   ByVal blue As Integer _) As Color
[C#]
public static Color FromArgb(intalpha,intred,intgreen,intblue);
[C++]
public: static Color FromArgb(intalpha,intred,intgreen,intblue);
[JScript]
public static function FromArgb(
   alpha : int,red : int,green : int,blue : int) : Color;

パラメータ

  • alpha
    アルファのコンポーネント。有効な値は 0 から 255 です。
  • red
    赤のコンポーネント。有効な値は 0 から 255 です。
  • green
    緑のコンポーネント。有効な値は 0 から 255 です。
  • blue
    青のコンポーネント。有効な値は 0 から 255 です。

戻り値

このメソッドが作成する Color 構造体。

使用例

[Visual Basic, C#] 次の例は、Windows フォームでの使用を意図してデザインされており、 Paint イベント ハンドラのパラメータである PaintEventArgs e が必要です。このコードは次のアクションを実行します。

  • 色が異なる 3 つのブラシを作成します。ブラシの作成に使用する各 Color 構造体は、4 つのコンポーネントの値 (アルファ、赤、緑、青) から作成されます。
  • 架空の三角形を使用して 3 つの円の位置を指定します。
  • 三角形の各頂点を中心とする 3 つの重なった円をそれぞれ異なるブラシで塗りつぶします。
 
Public Sub FromArgb_1(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
        
[C#] 
public void FromArgb_1(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);
}
        

[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

Color 構造体 | Color メンバ | System.Drawing 名前空間 | Color.FromArgb オーバーロードの一覧