KnownColor 列挙体
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Enumeration KnownColor


KnownColor 列挙体を使用してすべての値の名前および色を印刷する方法を方法を次のコード例に示します。この例は、Windows フォームでの使用を意図してデザインされています。フォームを作成し、次のコードを貼り付けます。フォームの Paint イベント処理メソッドで DisplayKnownColors メソッドを呼び出し、e を PaintEventArgs として渡します。
Private Sub DisplayKnownColors(ByVal e As PaintEventArgs) Me.Size = New Size(650, 550) Dim i As Integer ' Get all the values from the KnownColor enumeration. Dim colorsArray As System.Array = _ [Enum].GetValues(GetType(KnownColor)) Dim allColors(colorsArray.length) As KnownColor Array.Copy(colorsArray, allColors, colorsArray.Length) ' Loop through printing out the value's name in the colors ' they represent. Dim y As Single Dim x As Single = 10.0F For i = 0 To allColors.Length - 1 ' If x is a multiple of 30, start a new column. If (i > 0 And i Mod 30 = 0) Then x += 105.0F y = 15.0F Else ' Otherwise increment y by 15. y += 15.0F End If ' Create a custom brush from the color and use it to draw ' the brush's name. Dim aBrush As New SolidBrush(Color.FromName( _ allColors(i).ToString())) e.Graphics.DrawString(allColors(i).ToString(), _ Me.Font, aBrush, x, y) ' Dispose of the custom brush. aBrush.Dispose() Next End Sub
private void DisplayKnownColors(PaintEventArgs e) { this.Size = new Size(650, 550); // Get all the values from the KnownColor enumeration. System.Array colorsArray = Enum.GetValues(typeof(KnownColor)); KnownColor[] allColors = new KnownColor[colorsArray.Length]; Array.Copy(colorsArray, allColors, colorsArray.Length); // Loop through printing out the values' names in the colors // they represent. float y = 0; float x = 10.0F; for(int i = 0; i < allColors.Length; i++) { // If x is a multiple of 30, start a new column. if (i > 0 && i % 30 == 0) { x += 105.0F; y = 15.0F; } else { // Otherwise, increment y by 15. y += 15.0F; } // Create a custom brush from the color and use it to draw // the brush's name. SolidBrush aBrush = new SolidBrush(Color.FromName(allColors[i].ToString())); e.Graphics.DrawString(allColors[i].ToString(), this.Font, aBrush, x, y); // Dispose of the custom brush. aBrush.Dispose(); } }
private: void DisplayKnownColors( PaintEventArgs^ e ) { this->Size = System::Drawing::Size( 650, 550 ); // Get all the values from the KnownColor enumeration. System::Array^ colorsArray = Enum::GetValues( KnownColor::typeid ); array<KnownColor>^allColors = gcnew array<KnownColor>(colorsArray->Length); Array::Copy( colorsArray, allColors, colorsArray->Length ); // Loop through printing out the values' names in the colors // they represent. float y = 0; float x = 10.0F; for ( int i = 0; i < allColors->Length; i++ ) { // If x is a multiple of 30, start a new column. if ( i > 0 && i % 30 == 0 ) { x += 105.0F; y = 15.0F; } else { // Otherwise, increment y by 15. y += 15.0F; } // Create a custom brush from the color and use it to draw // the brush's name. SolidBrush^ aBrush = gcnew SolidBrush( Color::FromName( allColors[ i ].ToString() ) ); e->Graphics->DrawString( allColors[ i ].ToString(), this->Font, aBrush, x, y ); // Dispose of the custom brush. delete aBrush; } }
private void DisplayKnownColors(PaintEventArgs e) { this.set_Size(new Size(650, 550)); // Get all the values from the KnownColor enumeration. System.Array colorsArray = Enum.GetValues(KnownColor.class.ToType()); KnownColor allColors[] = new KnownColor[colorsArray.get_Length()]; Array.Copy(colorsArray, allColors, colorsArray.get_Length()); // Loop through printing out the values' names in the colors // they represent. float y = 0; float x = 10; for (int i = 0; i < allColors.length; i++) { // If x is a multiple of 30, start a new column. if (i > 0 && i % 30 == 0) { x += 105; y = 15; } else { // Otherwise, increment y by 15. y += 15; } // Create a custom brush from the color and use it to draw // the brush's name. SolidBrush aBrush = new SolidBrush(Color.FromName( allColors.get_Item(i).ToString())); e.get_Graphics().DrawString(allColors.get_Item(i).ToString(), this.get_Font(), aBrush, x, y); // Dispose of the custom brush. aBrush.Dispose(); } } //DisplayKnownColors

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- KnownColor 列挙体のページへのリンク