指定の新しいアルファ値を使用して、指定の Color 構造体から Color 構造体を作成します。このメソッドではアルファ値の 32 ビット値を渡すことができますが、そのアルファ値は 8 ビットに限定されます。
Overloads Public Shared Function FromArgb( _
ByVal alpha As Integer, _ ByVal baseColor As Color _) As Color
[C#]
public static Color FromArgb(intalpha,ColorbaseColor);
[C++]
public: static Color FromArgb(intalpha,ColorbaseColor);
[JScript]
public static function FromArgb(
alpha : int,baseColor : Color) : Color;
パラメータ
戻り値
このメソッドが作成する Color 構造体。
使用例
[Visual Basic, C#] 次の例は、Windows フォームでの使用を意図してデザインされており、 Paint イベント ハンドラのパラメータである PaintEventArgs e が必要です。このコードは次のアクションを実行します。
- 3 つのカラー コンポーネントの値 (赤、緑、青) から Color 構造体を作成します。3 つの Color 構造体は、それぞれ原色で作成されます。
- アルファ値の範囲を反復処理して、色のアルファ値を変更します。
- 各反復処理中、ブラシの色を変更した色に設定し、三角形をその色で塗りつぶします。
- 各原色に対してステップ 2 とステップ 3 の操作を繰り返します。
[Visual Basic, C#] アルファ値は完全には不透明にはならず、三角形が重複するため、色の組み合わせ効果を得ることができます。
Public Sub FromArgb_2_4(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
Dim x As Integer = 50 ' x coordinate of first red rectangle
Dim y As Integer = 50 ' y coordinate of first red rectangle
' 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 = 50 ' x coordinate of first green rectangle
y += 50 ' y coordinate of first green rectangle
' 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 = 50 ' x coordinate of first blue rectangle
y += 100 ' y coordinate of first blue rectangle
' 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
[C#]
public void FromArgb_2_4(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;
int x = 50; // x coordinate of first red rectangle
int y = 50; // y coordinate of first red rectangle
// 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; // x coordinate of first green rectangle
y += 50; // y coordinate of first green rectangle
// 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; // x coordinate of first blue rectangle
y += 100; // y coordinate of first blue rectangle
// 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;
}
}
[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 オーバーロードの一覧