Color.FromName メソッド
アセンブリ: System.Drawing (system.drawing.dll 内)

Dim name As String Dim returnValue As Color returnValue = Color.FromName(name)
戻り値
このメソッドが作成する Color。

定義済みの色は既知の色とも呼ばれ、KnownColor 列挙体の要素によって表されます。name パラメータが定義済みの色の有効な名前でない場合、FromName メソッドは ARGB 値が 0 (すべての ARGB コンポーネントが 0) の Color 構造体を作成します。

Color の G メンバ、B メンバ、R メンバ、A メンバ、FromName メンバ、および op_Implicit メンバを使ったコード例を次に示します。
この例は、Windows フォームでの使用を意図してデザインされています。コードをフォームに貼り付け、フォームの Paint イベント処理メソッドから PaintEventArgs の e を渡して ShowPropertiesOfSlateBlue メソッドを呼び出します。
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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からColor.FromName メソッドを検索する場合は、下記のリンクをクリックしてください。

- Color.FromName メソッドのページへのリンク