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 색의 문자열 표현입니다.

반환

htmlColornull인 경우 변환된 HTML 색을 나타내는 Color 구조체 또는 Empty입니다.

예외

htmlColor이 올바른 HTML 색 이름이 아닌 경우

예제

다음 예제는 Windows Forms 사용하도록 설계되었으며 이벤트 처리기의 Paint 매개 변수인 가 필요합니다.PaintEventArgse 코드는 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 구조체로 변환합니다.

적용 대상