Color.FromName(String) Color.FromName(String) Color.FromName(String) Color.FromName(String) Method

定義

定義済みの色の指定した名前から Color 構造体を作成します。Creates a Color structure from the specified name of a predefined 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 String String String

定義済みの色の名前である文字列。A string that is the name of a predefined color. 有効な名前は KnownColor 列挙体の要素の名前と同じです。Valid names are the same as the names of the elements of the KnownColor enumeration.

戻り値

このメソッドが作成する ColorThe Color that this method creates.

次のコード例では、ARGB、および Color のメンバーと FromNameImplicitメンバーを示します。The following code example demonstrates the A, R, G, B, and FromName members of a Color, and the Implicit member.

この例は、Windows フォームと共に使用するように設計されています。This example is designed to be used with a Windows Form. フォームにコードを貼り付けて、フォームの Paint イベント処理メソッドから ShowPropertiesOfSlateBlue メソッドを呼び出し、ePaintEventArgs として渡します。Paste the code into the form and call the ShowPropertiesOfSlateBlue method from the form's Paint event-handling method, passing e as 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 列挙体の要素によって表されます。A predefined color is also called a known color and is represented by an element of the KnownColor enumeration. name パラメーターが定義済みの色の有効な名前ではない場合、FromName メソッドは、ARGB 値が 0 (つまり、すべての ARGB コンポーネントが 0) の Color 構造体を作成します。If the name parameter is not the valid name of a predefined color, the FromName method creates a Color structure that has an ARGB value of 0 (that is, all ARGB components are 0).

適用対象