DrawItemEventArgsとは? わかりやすく解説

DrawItemEventArgs クラス

DrawItem イベントデータ提供します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Class DrawItemEventArgs
    Inherits EventArgs
Dim instance As DrawItemEventArgs
public class DrawItemEventArgs : EventArgs
public ref class DrawItemEventArgs : public
 EventArgs
public class DrawItemEventArgs extends EventArgs
public class DrawItemEventArgs extends
 EventArgs
解説解説
使用例使用例

オーナー描画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.Object
   System.EventArgs
    System.Windows.Forms.DrawItemEventArgs
       System.Windows.Forms.StatusBarDrawItemEventArgs
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DrawItemEventArgs メンバ
System.Windows.Forms 名前空間
DrawItemEventHandler
ComboBox クラス
ListBox
MenuItem
TabControl

DrawItemEventArgs コンストラクタ (Graphics, Font, Rectangle, Int32, DrawItemState)

フォント、状態、描画する表面、および描画する範囲指定して特定のコントロールの DrawItemEventArgs クラス新しインスタンス初期化します。

名前空間: System.Windows.Forms
アセンブリ: 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
)

パラメータ

graphics

描画実行される Graphics 表面

font

使用する Font通常、親コントロールFont プロパティなります

rect

描画実行範囲を表す Rectangle 境界

index

描画されている項目の System.Windows.Forms.Control.ControlCollection インデックス値。

state

コントロールの DrawItemState 情報

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DrawItemEventArgs コンストラクタ (Graphics, Font, Rectangle, Int32, DrawItemState, Color, Color)

フォント、状態、前景色、背景色描画する表面、および描画する範囲指定して特定のコントロールの DrawItemEventArgs クラス新しインスタンス初期化します。

名前空間: System.Windows.Forms
アセンブリ: 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
)

パラメータ

graphics

描画実行される Graphics 表面

font

使用する Font通常、親コントロールFont プロパティなります

rect

描画実行範囲を表す Rectangle 境界

index

描画されている項目の System.Windows.Forms.Control.ControlCollection インデックス値。

state

コントロールの DrawItemState 情報

foreColor

コントロール描画するための前景色を示す Color

backColor

コントロール描画するための背景色を示す Color

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DrawItemEventArgs コンストラクタ

DrawItemEventArgs クラス新しインスタンス初期化します。
オーバーロードの一覧オーバーロードの一覧

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

関連項目

DrawItemEventArgs クラス
DrawItemEventArgs メンバ
System.Windows.Forms 名前空間

DrawItemEventArgs プロパティ


DrawItemEventArgs メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

DrawItemEventArgs クラス
System.Windows.Forms 名前空間
DrawItemEventHandler
ComboBox クラス
ListBox
MenuItem
TabControl

DrawItemEventArgs メンバ

DrawItem イベントデータ提供します

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


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド DrawItemEventArgs オーバーロードされます。 DrawItemEventArgs クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

DrawItemEventArgs クラス
System.Windows.Forms 名前空間
DrawItemEventHandler
ComboBox クラス
ListBox
MenuItem
TabControl



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「DrawItemEventArgs」の関連用語

DrawItemEventArgsのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DrawItemEventArgsのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS