Language

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がEmptyされている場合に、翻訳された HTML 色またはhtmlColorを表すnull構造体。

例外

htmlColor が有効な HTML カラー名ではありません。

例

次の例は Windows フォームで使用できるように設計されており、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

注釈

このメソッドは、BLUE や Red などの HTML カラー名の文字列形式を GDI+ Color 構造体に変換します。

適用対象