DrawItemEventArgs クラス
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


DrawItem イベントは、ListBox コントロールや ComboBox コントロールなどのオーナー描画コントロールによって発生します。このデータには、項目のインデックス、Rectangle、描画が実行される Graphics など、指定した項目を描画するために必要な情報がすべて含まれています。

オーナー描画の ListBox 項目を作成する方法を次の例に示します。このコードでは、DrawMode プロパティを使用して、描画する項目が固定サイズであることを示し、DrawItem イベントを使用して、ListBox への各項目の描画を実行しています。この例のコードでは、イベント ハンドラへのパラメータとして渡された DrawItemEventArgs クラスのプロパティとメソッドを使用して項目を描画しています。この例は、listBox1 という名前の ListBox コントロールがフォームに既に追加されていて、DrawItem イベントがこの例のコードに定義されているイベント ハンドラで処理されることを前提にしています。この例では、"Apple"、"Orange"、"Plum" の 3 つのテキストの項目がこの順番で ListBox に追加されていることも想定しています。
Private Sub listBox1_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem ' Set the DrawMode property to draw fixed sized items. ListBox1.DrawMode = DrawMode.OwnerDrawFixed ' Draw the background of the ListBox control for each item. e.DrawBackground() ' Define the default color of the brush as black. Dim myBrush As Brush ' Determine the color of the brush to draw each item based on the index of the item to draw. Select Case (e.Index) Case 0 myBrush = Brushes.Red Case 1 myBrush = Brushes.Orange Case 2 myBrush = Brushes.Purple End Select ' Draw the current item text based on the current Font and the custom brush settings. e.Graphics.DrawString(ListBox1.Items(e.Index), e.Font, myBrush, New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)) ' If the ListBox has focus, draw a focus rectangle around the selected item. e.DrawFocusRectangle() End Sub
private void listBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { // Set the DrawMode property to draw fixed sized items. listBox1.DrawMode = DrawMode.OwnerDrawFixed; // Draw the background of the ListBox control for each item. e.DrawBackground(); // Define the default color of the brush as black. Brush myBrush = Brushes.Black; // Determine the color of the brush to draw each item based on the index of the item to draw. switch (e.Index) { case 0: myBrush = Brushes.Red; break; case 1: myBrush = Brushes.Orange; break; case 2: myBrush = Brushes.Purple; break; } // Draw the current item text based on the current Font and the custom brush settings. e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), e.Font, myBrush,e.Bounds ,StringFormat.GenericDefault); // If the ListBox has focus, draw a focus rectangle around the selected item. e.DrawFocusRectangle(); }
private: void listBox1_DrawItem( Object^ /*sender*/, System::Windows::Forms::DrawItemEventArgs^ e ) { // Set the DrawMode property to draw fixed sized items. listBox1->DrawMode = DrawMode::OwnerDrawFixed; // Draw the background of the ListBox control for each item. e->DrawBackground(); // Define the default color of the brush as black. Brush^ myBrush = Brushes::Black; // Determine the color of the brush to draw each item based on the index of the item to draw. switch ( e->Index ) { case 0: myBrush = Brushes::Red; break; case 1: myBrush = Brushes::Orange; break; case 2: myBrush = Brushes::Purple; break; } // Draw the current item text based on the current Font and the custom brush settings. e->Graphics->DrawString( listBox1->Items[ e->Index ]->ToString(), e->Font, myBrush, e->Bounds, StringFormat::GenericDefault ); // If the ListBox has focus, draw a focus rectangle around the selected item. e->DrawFocusRectangle(); }
private void listBox1_DrawItem(Object sender , System.Windows.Forms.DrawItemEventArgs e) { // Set the DrawMode property to draw fixed sized items. listBox1.set_DrawMode(DrawMode.OwnerDrawFixed); // Draw the background of the ListBox control for each item. e.DrawBackground(); // Create a new Brush and initialize to a Black colored brush // by default. Brush myBrush = Brushes.get_Black(); // Determine the color of the brush to draw each item based on the // index of the item to draw. switch (e.get_Index()) { case 0 : myBrush = Brushes.get_Red(); break; case 1 : myBrush = Brushes.get_Orange(); break; case 2 : myBrush = Brushes.get_Purple(); break; } // Draw the current item text based on the current Font and the custom // brush settings. e.get_Graphics().DrawString(System.Convert.ToString(listBox1. get_Items().get_Item(e.get_Index())), e.get_Font(), myBrush, RectangleF.op_Implicit(e.get_Bounds()), StringFormat. get_GenericDefault()); // If the ListBox has focus, draw a focus rectangle around the selected // item. e.DrawFocusRectangle(); } //listBox1_DrawItem

System.EventArgs
System.Windows.Forms.DrawItemEventArgs
System.Windows.Forms.StatusBarDrawItemEventArgs


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DrawItemEventArgs コンストラクタ (Graphics, Font, Rectangle, Int32, DrawItemState)
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Public Sub New ( _ graphics As Graphics, _ font As Font, _ rect As Rectangle, _ index As Integer, _ state As DrawItemState _ )
Dim graphics As Graphics Dim font As Font Dim rect As Rectangle Dim index As Integer Dim state As DrawItemState Dim instance As New DrawItemEventArgs(graphics, font, rect, index, state)
public DrawItemEventArgs ( Graphics graphics, Font font, Rectangle rect, int index, DrawItemState state )
public: DrawItemEventArgs ( Graphics^ graphics, Font^ font, Rectangle rect, int index, DrawItemState state )
public DrawItemEventArgs ( Graphics graphics, Font font, Rectangle rect, int index, DrawItemState state )
public function DrawItemEventArgs ( graphics : Graphics, font : Font, rect : Rectangle, index : int, state : DrawItemState )

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DrawItemEventArgs コンストラクタ (Graphics, Font, Rectangle, Int32, DrawItemState, Color, Color)
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Public Sub New ( _ graphics As Graphics, _ font As Font, _ rect As Rectangle, _ index As Integer, _ state As DrawItemState, _ foreColor As Color, _ backColor As Color _ )
Dim graphics As Graphics Dim font As Font Dim rect As Rectangle Dim index As Integer Dim state As DrawItemState Dim foreColor As Color Dim backColor As Color Dim instance As New DrawItemEventArgs(graphics, font, rect, index, state, foreColor, backColor)
public DrawItemEventArgs ( Graphics graphics, Font font, Rectangle rect, int index, DrawItemState state, Color foreColor, Color backColor )
public: DrawItemEventArgs ( Graphics^ graphics, Font^ font, Rectangle rect, int index, DrawItemState state, Color foreColor, Color backColor )
public DrawItemEventArgs ( Graphics graphics, Font font, Rectangle rect, int index, DrawItemState state, Color foreColor, Color backColor )
public function DrawItemEventArgs ( graphics : Graphics, font : Font, rect : Rectangle, index : int, state : DrawItemState, foreColor : Color, backColor : Color )

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DrawItemEventArgs コンストラクタ

名前 | 説明 |
---|---|
DrawItemEventArgs (Graphics, Font, Rectangle, Int32, DrawItemState) | フォント、状態、描画する表面、および描画する範囲を指定して、特定のコントロールの DrawItemEventArgs クラスの新しいインスタンスを初期化します。 |
DrawItemEventArgs (Graphics, Font, Rectangle, Int32, DrawItemState, Color, Color) | フォント、状態、前景色、背景色、描画する表面、および描画する範囲を指定して、特定のコントロールの DrawItemEventArgs クラスの新しいインスタンスを初期化します。 |

DrawItemEventArgs プロパティ

名前 | 説明 | |
---|---|---|
![]() | BackColor | 描画されている項目の背景色を取得します。 |
![]() | Bounds | 描画されている項目の境界を表す四角形を取得します。 |
![]() | Font | 描画されている項目に割り当てられているフォントを取得します。 |
![]() | ForeColor | 描画されている項目の前景色を取得します。 |
![]() | Graphics | 項目を描画するグラフィックス表面を取得します。 |
![]() | Index | 描画されている項目のインデックス値を取得します。 |
![]() | State | 描画されている項目の状態を取得します。 |

DrawItemEventArgs メソッド

名前 | 説明 | |
---|---|---|
![]() | DrawBackground | DrawItemEventArgs コンストラクタで指定されている境界内に適切な色で背景を描画します。 |
![]() | DrawFocusRectangle | DrawItemEventArgs コンストラクタで指定されている境界内に、フォーカスを示す四角形を描画します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

DrawItemEventArgs メンバ
DrawItemEventArgs データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | BackColor | 描画されている項目の背景色を取得します。 |
![]() | Bounds | 描画されている項目の境界を表す四角形を取得します。 |
![]() | Font | 描画されている項目に割り当てられているフォントを取得します。 |
![]() | ForeColor | 描画されている項目の前景色を取得します。 |
![]() | Graphics | 項目を描画するグラフィックス表面を取得します。 |
![]() | Index | 描画されている項目のインデックス値を取得します。 |
![]() | State | 描画されている項目の状態を取得します。 |

名前 | 説明 | |
---|---|---|
![]() | DrawBackground | DrawItemEventArgs コンストラクタで指定されている境界内に適切な色で背景を描画します。 |
![]() | DrawFocusRectangle | DrawItemEventArgs コンストラクタで指定されている境界内に、フォーカスを示す四角形を描画します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

- DrawItemEventArgsのページへのリンク