다음을 통해 공유


Color.FromName 메서드

미리 정의된 색의 지정된 이름으로 Color 구조체를 만듭니다.

네임스페이스: System.Drawing
어셈블리: System.Drawing(system.drawing.dll)

구문

‘선언
Public Shared Function FromName ( _
    name As String _
) As Color
‘사용 방법
Dim name As String
Dim returnValue As Color

returnValue = Color.FromName(name)
public static Color FromName (
    string name
)
public:
static Color FromName (
    String^ name
)
public static Color FromName (
    String name
)
public static function FromName (
    name : String
) : Color

매개 변수

  • name
    미리 정의된 색의 이름인 문자열입니다. 유효한 이름은 KnownColor 열거 요소의 이름과 동일합니다.

반환 값

이 메서드가 만드는 Color입니다.

설명

미리 정의된 색은 이미 알려진 색이라고도 부르며, KnownColor 열거형의 요소로 나타냅니다. name 매개 변수가 미리 정의된 색의 유효한 이름이 아닌 경우 FromName 메서드는 ARGB 값이 0(즉, 모든 ARGB 구성 요소가 0)인 Color 구조체를 만듭니다.

예제

다음 코드 예제에서는 Colorop_Implicit 멤버의 G, B, R, AFromName 멤버를 보여 줍니다.

이 예제는 Windows Form과 함께 사용해야 합니다. 폼에 코드를 붙여넣은 후 폼의 Paint 이벤트 처리 메서드에서 ShowPropertiesOfSlateBlue 메서드를 호출하고 e를 PaintEventArgs로 전달합니다.

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
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));
}
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");
    ubyte g = slateBlue.get_G();
    ubyte b = slateBlue.get_B();
    ubyte r = slateBlue.get_R();
    ubyte a = slateBlue.get_A();
    String text = String.Format(
        "Slate Blue has these ARGB values: Alpha:{0}, "  
        + "red:{1}, green: {2}, blue {3}", 
        new Object[] { (UInt16)a, (UInt16)r, (UInt16)g, (UInt16)b });

    e.get_Graphics().DrawString(text, 
        new Font(this.get_Font(), FontStyle.Italic), 
        new SolidBrush(slateBlue), 
        new RectangleF(new PointF(0, 0), 
        Size.op_Implicit(this.get_Size())));
} //ShowPropertiesOfSlateBlue

플랫폼

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

Color 구조체
Color 멤버
System.Drawing 네임스페이스