言語

Color.FromName(String) メソッド

定義

定義済みの色の指定した名前から Color 構造体を作成します。

public:
 static System::Drawing::Color FromName(System::String ^ name);
public static System.Drawing.Color FromName(string name);
static member FromName : string -> System.Drawing.Color
Public Shared Function FromName (name As String) As Color

パラメーター

name
String

定義済みの色の名前を表す文字列。 有効な名前は、 KnownColor 列挙体の要素の名前と同じです。

返品

このメソッドが作成する Color

次のコード例は、ARGBFromName、およびColorメンバー、およびImplicit メンバーを示しています。

この例は、Windows フォームで使用するように設計されています。 コードをフォームに貼り付け、フォームの ShowPropertiesOfSlateBlue イベント処理メソッドから Paint メソッドを呼び出し、eとしてPaintEventArgs渡します。

void ShowPropertiesOfSlateBlue( PaintEventArgs^ e )
{
   Color slateBlue = Color::FromName( "SlateBlue" );
   Byte g = slateBlue.G;
   Byte b = slateBlue.B;
   Byte r = slateBlue.R;
   Byte a = slateBlue.A;
   array<Object^>^temp0 = {a,r,g,b};
   String^ text = String::Format( "Slate Blue has these ARGB values: Alpha:{0}, "
   "red:{1}, green: {2}, blue {3}", temp0 );
   e->Graphics->DrawString( text, gcnew System::Drawing::Font( this->Font,FontStyle::Italic ), gcnew SolidBrush( slateBlue ), RectangleF(PointF(0.0F,0.0F),this->Size) );
}
private void ShowPropertiesOfSlateBlue(PaintEventArgs e)
{
    Color slateBlue = Color.FromName("SlateBlue");
    byte g = slateBlue.G;
    byte b = slateBlue.B;
    byte r = slateBlue.R;
    byte a = slateBlue.A;
    string text = String.Format("Slate Blue has these ARGB values: Alpha:{0}, " +
        "red:{1}, green: {2}, blue {3}", new object[]{a, r, g, b});
    e.Graphics.DrawString(text, 
        new Font(this.Font, FontStyle.Italic), 
        new SolidBrush(slateBlue), 
        new RectangleF(new PointF(0.0F, 0.0F), this.Size));
}
Private Sub ShowPropertiesOfSlateBlue(ByVal e As PaintEventArgs)
    Dim slateBlue As Color = Color.FromName("SlateBlue")
    Dim g As Byte = slateBlue.G
    Dim b As Byte = slateBlue.B
    Dim r As Byte = slateBlue.R
    Dim a As Byte = slateBlue.A
    Dim text As String = _
    String.Format("Slate Blue has these ARGB values: Alpha:{0}, " _
       & "red:{1}, green: {2}, blue {3}", New Object() {a, r, g, b})
    e.Graphics.DrawString(text, New Font(Me.Font, FontStyle.Italic), _
        New SolidBrush(slateBlue), _
        New RectangleF(New PointF(0.0F, 0.0F), _
        Size.op_Implicit(Me.Size)))
End Sub

注釈

定義済みの色は既知の色とも呼ばれ、 KnownColor 列挙体の要素によって表されます。 name パラメーターが定義済みの色の有効な名前でない場合、FromName メソッドは ARGB 値が 0 (つまり、すべての ARGB コンポーネントが 0) を持つColor構造体を作成します。

適用対象