DrawItemEventHandler デリゲートとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DrawItemEventHandler デリゲートの意味・解説 

DrawItemEventHandler デリゲート

ComboBoxListBox、MenuItem、TabControl の各コントロールいずれかDrawItem イベント処理するメソッド表します

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

Public Delegate Sub DrawItemEventHandler
 ( _
    sender As Object, _
    e As DrawItemEventArgs _
)
Dim instance As New DrawItemEventHandler(AddressOf
 HandlerMethod)
public delegate void DrawItemEventHandler (
    Object sender,
    DrawItemEventArgs e
)
public delegate void DrawItemEventHandler (
    Object^ sender, 
    DrawItemEventArgs^ e
)
/** @delegate */
public delegate void DrawItemEventHandler (
    Object sender, 
    DrawItemEventArgs e
)
JScript では、デリゲート使用できますが、新規に宣言することはできません。

パラメータ

sender

イベントソース

e

イベント データ格納している DrawItemEventArgs。

解説解説
使用例使用例

オーナー描画メニュー項目を持つメニュー次のコード例示します。この例では、AddHandler ステートメントAddressOf 演算子使用して、MenuItem.DrawItem イベント処理するデリゲート指定してます。この例を実行するには、次のコードフォーム貼り付けます。このフォームは、System 名前空間System.Windows.Forms 名前空間、および System.Drawing System.Drawing 名前空間インポートます。必ずすべてのイベントイベント処理メソッド関連付けるようにしてください

' Declare the MainMenu control.
Friend WithEvents MainMenu1 As
 System.Windows.Forms.MainMenu

' Declare MenuItem2 as With-Events because it will be user drawn.
Friend WithEvents MenuItem2 As
 System.Windows.Forms.MenuItem


Private Sub InitializeMenu()

    ' Create MenuItem1, which will be drawn by the operating system.
    Dim MenuItem1 As New
 MenuItem("Regular Menu Item")

    ' Create MenuItem2.
    MenuItem2 = New MenuItem("Custom Menu Item")

    ' Set OwnerDraw property to true. This requires handling the
    ' DrawItem event for this menu item.
    MenuItem2.OwnerDraw = True

    'Add the event-handler delegate to handle the DrawItem event.
    AddHandler MenuItem2.DrawItem, New DrawItemEventHandler(AddressOf
 DrawCustomMenuItem)

    ' Add the items to the menu.
    MainMenu1 = New MainMenu(New MenuItem()
 {MenuItem1, MenuItem2})

    ' Add the menu to the form.
    Me.Menu = Me.MainMenu1
End Sub

' Draw the custom menu item.
Private Sub DrawCustomMenuItem(ByVal
 sender As Object, ByVal
 e As _
        System.Windows.Forms.DrawItemEventArgs)

    ' Cast the sender to MenuItem so you can access text property.
    Dim customItem As MenuItem = CType(sender,
 MenuItem)

    ' Create a Brush and a Font to draw the MenuItem.
    Dim aBrush As System.Drawing.Brush = System.Drawing.Brushes.DarkMagenta
    Dim aFont As New Font("Garamond",
 10, FontStyle.Italic, _
        GraphicsUnit.Point)

    ' Get the size of the text to use later to draw an ellipse
    ' around the item.
    Dim stringSize As SizeF = e.Graphics.MeasureString(
 _
        customItem.Text, aFont)

    ' Draw the item and then draw the ellipse.
    e.Graphics.DrawString(customItem.Text, aFont, _
        aBrush, e.Bounds.X, e.Bounds.Y)
    e.Graphics.DrawEllipse(New Pen(System.Drawing.Color.Black,
 2), _
        New Rectangle(e.Bounds.X, e.Bounds.Y, stringSize.Width,
 _
        stringSize.Height))
End Sub
// Declare the MainMenu control.
internal System.Windows.Forms.MainMenu MainMenu1;

// Declare MenuItem2 as With-Events because it will be user drawn.
internal System.Windows.Forms.MenuItem MenuItem2;


private void InitializeMenu()
{

    // Create MenuItem1, which will be drawn by the operating system.
    MenuItem MenuItem1 = new MenuItem("Regular Menu Item");

    // Create MenuItem2.
    MenuItem2 = new MenuItem("Custom Menu Item");

    // Set OwnerDraw property to true. This requires handling the
    // DrawItem event for this menu item.
    MenuItem2.OwnerDraw = true;

    //Add the event-handler delegate to handle the DrawItem event.
    MenuItem2.DrawItem += new DrawItemEventHandler(DrawCustomMenuItem);
    
  // Add the items to the menu.
    MainMenu1 = new MainMenu(new MenuItem[]{MenuItem1,
 MenuItem2});                                                                  
                                                    

    // Add the menu to the form.
    this.Menu = this.MainMenu1;
}

// Draw the custom menu item.
private void DrawCustomMenuItem(object sender,
 
    DrawItemEventArgs e)
{

    // Cast the sender to MenuItem so you can access text property.
    MenuItem customItem = (MenuItem) sender;

    // Create a Brush and a Font to draw the MenuItem.
    System.Drawing.Brush aBrush = System.Drawing.Brushes.DarkMagenta;
    Font aFont = new Font("Garamond", 10, 
        FontStyle.Italic, GraphicsUnit.Point);

    // Get the size of the text to use later to draw an ellipse
    // around the item.
    SizeF stringSize = e.Graphics.MeasureString(
        customItem.Text, aFont);

    // Draw the item and then draw the ellipse.
    e.Graphics.DrawString(customItem.Text, aFont, 
        aBrush, e.Bounds.X, e.Bounds.Y);
    e.Graphics.DrawEllipse(new Pen(System.Drawing.Color.Black,
 2),
        new Rectangle(e.Bounds.X, e.Bounds.Y, 
        (System.Int32)stringSize.Width,
        (System.Int32)stringSize.Height));
}
internal:
   // Declare the MainMenu control.
   System::Windows::Forms::MainMenu^ MainMenu1;

   // Declare MenuItem2 as With-Events because it will be user drawn.
   System::Windows::Forms::MenuItem^ MenuItem2;

private:
   void InitializeMenu()
   {
      
      // Create MenuItem1, which will be drawn by the operating system.
      MenuItem^ MenuItem1 = gcnew MenuItem( "Regular Menu Item" );
      
      // Create MenuItem2.
      MenuItem2 = gcnew MenuItem( "Custom Menu Item" );
      
      // Set OwnerDraw property to true. This requires handling the
      // DrawItem event for this menu item.
      MenuItem2->OwnerDraw = true;
      
      //Add the event-handler delegate to handle the DrawItem event.
      MenuItem2->DrawItem += gcnew DrawItemEventHandler( this,
 &Form1::DrawCustomMenuItem );
      
      // Add the items to the menu.
      array<MenuItem^>^temp0 = {MenuItem1,MenuItem2};
      MainMenu1 = gcnew MainMenu( temp0 );
      
      // Add the menu to the form.
      this->Menu = this->MainMenu1;
   }

   // Draw the custom menu item.
   void DrawCustomMenuItem( Object^ sender, DrawItemEventArgs^
 e )
   {
      // Cast the sender to MenuItem so you can access text property.
      MenuItem^ customItem = dynamic_cast<MenuItem^>(sender);
      
      // Create a Brush and a Font to draw the MenuItem.
      System::Drawing::Brush^ aBrush = System::Drawing::Brushes::DarkMagenta;
      System::Drawing::Font^ aFont = gcnew System::Drawing::Font( "Garamond",10,FontStyle::Italic,GraphicsUnit::Point
 );
      
      // Get the size of the text to use later to draw an ellipse
      // around the item.
      SizeF stringSize = e->Graphics->MeasureString( customItem->Text, aFont
 );
      
      // Draw the item and then draw the ellipse.
      e->Graphics->DrawString( customItem->Text, aFont, aBrush, (float)e->Bounds.X,
 (float)e->Bounds.Y );
      e->Graphics->DrawEllipse( gcnew Pen( System::Drawing::Color::Black,2
 ), Rectangle(e->Bounds.X,e->Bounds.Y,(System::Int32)stringSize.Width,(System::Int32)stringSize.Height)
 );
   }
// Declare the MainMenu control.
System.Windows.Forms.MainMenu mainMenu1;

// Declare MenuItem2 as With-Events because it will be user drawn.
System.Windows.Forms.MenuItem menuItem2;

private void InitializeMenu()
{
    // Create MenuItem1, which will be drawn by the operating system.
    MenuItem menuItem1 = new MenuItem("Regular Menu Item");
    // Create MenuItem2.
    menuItem2 = new MenuItem("Custom Menu Item");
    // Set OwnerDraw property to true. This requires handling the
    // DrawItem event for this menu item.
    menuItem2.set_OwnerDraw(true);
    //Add the event-handler delegate to handle the DrawItem event.
    menuItem2.add_DrawItem(new DrawItemEventHandler(DrawCustomMenuItem));
    // Add the items to the menu.
    mainMenu1 = new MainMenu(new MenuItem[]
 { menuItem1, menuItem2 });
    // Add the menu to the form.
    this.set_Menu(this.mainMenu1);
} //InitializeMenu

// Draw the custom menu item.
private void DrawCustomMenuItem(Object sender,
 DrawItemEventArgs e)
{
    // Cast the sender to MenuItem so you can access text property.
    MenuItem customItem = (MenuItem)sender;
    // Create a Brush and a Font to draw the MenuItem.
    System.Drawing.Brush aBrush = System.Drawing.Brushes.get_DarkMagenta();
    Font aFont =
        new Font("Garamond", 10, FontStyle.Italic, GraphicsUnit.Point);
    // Get the size of the text to use later to draw an ellipse
    // around the item.
    SizeF stringSize =
        e.get_Graphics().MeasureString(customItem.get_Text(), aFont);
    // Draw the item and then draw the ellipse.
    e.get_Graphics().
        DrawString(customItem.get_Text(), aFont, aBrush,
        e.get_Bounds().get_X(), e.get_Bounds().get_Y());
    e.get_Graphics().
        DrawEllipse(new Pen(System.Drawing.Color.get_Black(),
 2),
        new Rectangle(e.get_Bounds().get_X(), e.get_Bounds().get_Y()
,
        System.Convert.ToInt32((System.Int32)stringSize.get_Width()),
        System.Convert.ToInt32((System.Int32)stringSize.get_Height())));
} //DrawCustomMenuItem
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からDrawItemEventHandler デリゲートを検索した結果を表示しています。
Weblioに収録されているすべての辞書からDrawItemEventHandler デリゲートを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からDrawItemEventHandler デリゲートを検索

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

辞書ショートカット

すべての辞書の索引

「DrawItemEventHandler デリゲート」の関連用語

DrawItemEventHandler デリゲートのお隣キーワード
検索ランキング

   

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



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

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

©2024 GRAS Group, Inc.RSS