4 つの 8 ビット ARGB コンポーネント (アルファ、赤、緑、青) 値から Color 構造体を作成します。
オーバーロードの一覧
32 ビットの ARGB 値から Color 構造体を作成します。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function FromArgb(Integer) As Color
指定の新しいアルファ値を使用して、指定の Color 構造体から Color 構造体を作成します。このメソッドではアルファ値の 32 ビット値を渡すことができますが、そのアルファ値は 8 ビットに限定されます。
[Visual Basic] Overloads Public Shared Function FromArgb(Integer, Color) As Color
[JScript] public static function FromArgb(int, Color) : Color;
指定の 8 ビット カラー値 (赤、緑、青) から Color 構造体を作成します。アルファ値は暗黙的に 255 (完全不透明) になります。このメソッドでは各カラー コンポーネントの 32 ビット値を渡すことができますが、各カラー コンポーネントの値は 8 ビットに限定されます。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Shared Function FromArgb(Integer, Integer, Integer) As Color
[JScript] public static function FromArgb(int, int, int) : Color;
4 つの ARGB コンポーネント (アルファ、赤、緑、青) 値から Color 構造体を作成します。このメソッドでは各コンポーネントの 32 ビット値を渡すことができますが、各コンポーネントの値は 8 ビットに限定されます。
[Visual Basic] Overloads Public Shared Function FromArgb(Integer, Integer, Integer, Integer) As Color
[JScript] public static function FromArgb(int, int, int, int) : Color;
使用例
[Visual Basic, C#] 次の例は、Windows フォームでの使用を意図してデザインされており、 Paint イベント ハンドラのパラメータである PaintEventArgs e が必要です。このコードは次のアクションを実行します。
- 色が異なる 3 つのブラシを作成します。ブラシの作成に使用する各 Color 構造体は、4 つのコンポーネントの値 (アルファ、赤、緑、青) から作成されます。
- 架空の三角形を使用して 3 つの円の位置を指定します。
- 三角形の各頂点を中心とする 3 つの重なった円をそれぞれ異なるブラシで塗りつぶします。
[Visual Basic, C#] メモ ここでは、FromArgb のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。
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# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。