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입니다.

예제

다음 코드 예제에서는 A, , R, GBFromName 멤버의 및 멤버를 Color보여 줍니다Implicit.

이 예제는 Windows Form과 함께 사용하도록 설계되었습니다. 코드를 양식에 붙여넣고 양식의 Paint 이벤트 처리 메서드에서 메서드를 호출 ShowPropertiesOfSlateBlue 하여 로 PaintEventArgs전달합니다e.

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인 구조체를 만듭니다 Color (즉, 모든 ARGB 구성 요소는 0임).

적용 대상