ColorTranslator.FromHtml(String) 메서드

정의

HTML 색 표현을 GDI+ Color 구조체로 변환합니다.

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

매개 변수

htmlColor
String

번역할 Html 색의 문자열 표현입니다.

반품

Color 번역된 HTML 색을 나타내는 구조체입니다.EmptyhtmlColornull

예외

htmlColor 가 유효한 HTML 색 이름이 아닌 경우

예제

다음 예제는 Windows Forms에서 사용하도록 설계되었으며 이벤트 처리기의 매개 변수 PaintEventArgs 인 필수 ePaint요소입니다. 이 코드는 HTML 색 이름을 구조체로 Color 변환한 다음 해당 색을 사용하여 사각형을 채웁니다.

public:
   void FromHtml_Example( PaintEventArgs^ e )
   {
      // Create a string representation of an HTML color.
      String^ htmlColor = "Blue";

      // Translate htmlColor to a GDI+ Color structure.
      Color myColor = ColorTranslator::FromHtml( htmlColor );

      // Fill a rectangle with myColor.
      e->Graphics->FillRectangle( gcnew SolidBrush( myColor ), 0, 0, 100, 100 );
   }
public void FromHtml_Example(PaintEventArgs e)
{
    // Create a string representation of an HTML color.
    string htmlColor = "Blue";
             
    // Translate htmlColor to a GDI+ Color structure.
    Color myColor = ColorTranslator.FromHtml(htmlColor);
             
    // Fill a rectangle with myColor.
    e.Graphics.FillRectangle( new SolidBrush(myColor), 0, 0, 
        100, 100);
}
Public Sub FromHtml_Example(ByVal e As PaintEventArgs)

    ' Create a string representation of an HTML color.
    Dim htmlColor As String = "Blue"

    ' Translate htmlColor to a GDI+ Color structure.
    Dim myColor As Color = ColorTranslator.FromHtml(htmlColor)

    ' Fill a rectangle with myColor.
    e.Graphics.FillRectangle(New SolidBrush(myColor), 0, 0, 100, 100)
End Sub

설명

이 메서드는 HTML 색 이름(예: 파랑 또는 빨강)의 문자열 표현을 GDI+ Color 구조체로 변환합니다.

적용 대상