ComboBox.DrawMode プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ComboBox.DrawMode プロパティの意味・解説 

ComboBox.DrawMode プロパティ

リストの要素描画処理するのは、コードオペレーティング システムのどちらであるかを示す値を取得または設定します

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

Public Property DrawMode As
 DrawMode
Dim instance As ComboBox
Dim value As DrawMode

value = instance.DrawMode

instance.DrawMode = value
public DrawMode DrawMode { get; set;
 }
public:
property DrawMode DrawMode {
    DrawMode get ();
    void set (DrawMode value);
}
/** @property */
public DrawMode get_DrawMode ()

/** @property */
public void set_DrawMode (DrawMode value)
public function get DrawMode
 () : DrawMode

public function set DrawMode
 (value : DrawMode)

プロパティ
DrawMode 列挙値の 1 つ既定値Normal です。

例外例外
例外種類条件

InvalidEnumArgumentException

値が、有効な DrawMode 列挙値ではありません。

使用例使用例

DrawMode プロパティOwnerDrawnVariable設定し、DrawItem イベントおよび MeasureItem イベント処理してオーナー描画コンボ ボックス作成する方法次のコード例示します。この例はまた、DropDownWidth プロパティおよび DropDownStyle プロパティ設定方法示してます。この例を実行するには、次のコードフォーム貼り付けます。そして、フォームコンストラクタまたは Load イベントInitializeComboBox メソッド呼び出します。

Friend WithEvents ComboBox1 As
 System.Windows.Forms.ComboBox
Private animals() As String
  
' This method initializes the owner-drawn combo box.
' The drop-down width is set much wider than the size of the combo box
' to accomodate the large items in the list.  The drop-down style is
 set to 
' ComboBox.DropDown, which requires the user to click on the arrow to
 
' see the list.
Private Sub InitializeComboBox()
    Me.ComboBox1 = New ComboBox
    Me.ComboBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable
    Me.ComboBox1.Location = New System.Drawing.Point(10,
 20)
    Me.ComboBox1.Name = "ComboBox1"
    Me.ComboBox1.Size = New System.Drawing.Size(100,
 120)
    Me.ComboBox1.DropDownWidth = 250
    Me.ComboBox1.TabIndex = 0
    Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDown
    animals = New String() {"Elephant",
 "c r o c o d i l e", "lion"}
    ComboBox1.DataSource = animals
    Me.Controls.Add(Me.ComboBox1)
End Sub

' If you set the Draw property to DrawMode.OwnerDrawVariable, 
' you must handle the MeasureItem event. This event handler 
' will set the height and width of each item before it is drawn. 
 Private Sub ComboBox1_MeasureItem(ByVal
 sender As Object, _
    ByVal e As System.Windows.Forms.MeasureItemEventArgs)
 _
        Handles ComboBox1.MeasureItem

    Select Case e.Index
        Case 0
            e.ItemHeight = 45
        Case 1
            e.ItemHeight = 20
        Case 2
            e.ItemHeight = 35
    End Select
    e.ItemWidth = 260

End Sub

' You must handle the DrawItem event for owner-drawn combo boxes.  
' This event handler changes the color, size and font of an 
' item based on its position in the array.
Private Sub ComboBox1_DrawItem(ByVal
 sender As Object,  _ 
    ByVal e As System.Windows.Forms.DrawItemEventArgs)
 _
    Handles ComboBox1.DrawItem

    Dim size As Single
    Dim myFont As System.Drawing.Font
    Dim family As FontFamily

    Dim animalColor As New
 System.Drawing.Color
    Select Case e.Index
        Case 0
            size = 30
            animalColor = System.Drawing.Color.Gray
            family = FontFamily.GenericSansSerif
        Case 1
            size = 10
            animalColor = System.Drawing.Color.LawnGreen
            family = FontFamily.GenericMonospace
        Case 2
            size = 15
            animalColor = System.Drawing.Color.Tan
            family = FontFamily.GenericSansSerif
    End Select

    ' Draw the background of the item.
    e.DrawBackground()

    ' Create a square filled with the animals color. Vary the size
    ' of the rectangle based on the length of the animals name.
    Dim rectangle As Rectangle = New
 Rectangle(2, e.Bounds.Top + 2, _
        e.Bounds.Height, e.Bounds.Height - 4)
    e.Graphics.FillRectangle(New SolidBrush(animalColor), rectangle)

    ' Draw each string in the array, using a different size, color,
    ' and font for each item.
    myFont = New Font(family, size, FontStyle.Bold)
    e.Graphics.DrawString(animals(e.Index), myFont, System.Drawing.Brushes.Black,
 _
        New RectangleF(e.Bounds.X + rectangle.Width, e.Bounds.Y,
 _ 
        e.Bounds.Width, e.Bounds.Height))

    ' Draw the focus rectangle if the mouse hovers over an item.
    e.DrawFocusRectangle()
End Sub

internal System.Windows.Forms.ComboBox ComboBox1;
private string[] animals;
  
// This method initializes the owner-drawn combo box.
// The drop-down width is set much wider than the size of the combo
 box
// to accomodate the large items in the list.  The drop-down style is
 set to 
// ComboBox.DropDown, which requires the user to click on the arrow
 to 
// see the list.
private void InitializeComboBox()
{
    this.ComboBox1 = new ComboBox();
    this.ComboBox1.DrawMode = 
        System.Windows.Forms.DrawMode.OwnerDrawVariable;
    this.ComboBox1.Location = new System.Drawing.Point(10,
 20);
    this.ComboBox1.Name = "ComboBox1";
    this.ComboBox1.Size = new System.Drawing.Size(100,
 120);
    this.ComboBox1.DropDownWidth = 250;
    this.ComboBox1.TabIndex = 0;
    this.ComboBox1.DropDownStyle = ComboBoxStyle.DropDown;
    animals = new string[]{"Elephant",
 "c r o c o d i l e", "lion"};
    ComboBox1.DataSource = animals;
    this.Controls.Add(this.ComboBox1);

    // Hook up the MeasureItem and DrawItem events
    this.ComboBox1.DrawItem += 
        new DrawItemEventHandler(ComboBox1_DrawItem);
    this.ComboBox1.MeasureItem += 
        new MeasureItemEventHandler(ComboBox1_MeasureItem);
}

// If you set the Draw property to DrawMode.OwnerDrawVariable, 
// you must handle the MeasureItem event. This event handler 
// will set the height and width of each item before it is drawn. 
private void ComboBox1_MeasureItem(object sender,
 
    System.Windows.Forms.MeasureItemEventArgs e)
{

    switch(e.Index)
    {
        case 0:
            e.ItemHeight = 45;
            break;
        case 1:
            e.ItemHeight = 20;
            break;
        case 2:
            e.ItemHeight = 35;
            break;
    }
    e.ItemWidth = 260;

}

// You must handle the DrawItem event for owner-drawn combo boxes. 
 
// This event handler changes the color, size and font of an 
// item based on its position in the array.
private void ComboBox1_DrawItem(object sender,
 
    System.Windows.Forms.DrawItemEventArgs e)
{

    float size = 0;
    System.Drawing.Font myFont;
    FontFamily family = null;

    System.Drawing.Color animalColor = new System.Drawing.Color();
    switch(e.Index)
    {
        case 0:
            size = 30;
            animalColor = System.Drawing.Color.Gray;
            family = FontFamily.GenericSansSerif;
            break;
        case 1:
            size = 10;
            animalColor = System.Drawing.Color.LawnGreen;
            family = FontFamily.GenericMonospace;
            break;
        case 2:
            size = 15;
            animalColor = System.Drawing.Color.Tan;
            family = FontFamily.GenericSansSerif;
            break;
    }

    // Draw the background of the item.
    e.DrawBackground();

    // Create a square filled with the animals color. Vary the size
    // of the rectangle based on the length of the animals name.
    Rectangle rectangle = new Rectangle(2, e.Bounds.Top+2, 
            e.Bounds.Height, e.Bounds.Height-4);
    e.Graphics.FillRectangle(new SolidBrush(animalColor), rectangle);

    // Draw each string in the array, using a different size, color
,
    // and font for each item.
    myFont = new Font(family, size, FontStyle.Bold);
    e.Graphics.DrawString(animals[e.Index], myFont, System.Drawing.Brushes.Black,
 new RectangleF(e.Bounds.X+rectangle.Width, e.Bounds.Y, e.Bounds.Width,
 e.Bounds.Height));

    // Draw the focus rectangle if the mouse hovers over an item.
    e.DrawFocusRectangle();
}

internal:
   System::Windows::Forms::ComboBox^ ComboBox1;

private:
   array<String^>^ animals;

   // This method initializes the owner-drawn combo box.
   // The drop-down width is set much wider than the size of the combo
 box
   // to accomodate the large items in the list.  The drop-down style is
 set to 
   // ComboBox.DropDown, which requires the user to click on the arrow
 to 
   // see the list.
   void InitializeComboBox()
   {
      this->ComboBox1 = gcnew ComboBox;
      this->ComboBox1->DrawMode = System::Windows::Forms::DrawMode::OwnerDrawVariable;
      this->ComboBox1->Location = System::Drawing::Point(
 10, 20 );
      this->ComboBox1->Name = "ComboBox1";
      this->ComboBox1->Size = System::Drawing::Size( 100,
 120 );
      this->ComboBox1->DropDownWidth = 250;
      this->ComboBox1->TabIndex = 0;
      this->ComboBox1->DropDownStyle = ComboBoxStyle::DropDown;
      animals = gcnew array<String^>{"Elephant","c r o c o d
 i l e","lion"};
      ComboBox1->DataSource = animals;
      this->Controls->Add( this->ComboBox1
 );
      
      // Hook up the MeasureItem and DrawItem events
      this->ComboBox1->DrawItem +=
         gcnew DrawItemEventHandler( this, &Form1::ComboBox1_DrawItem
 );
      this->ComboBox1->MeasureItem +=
         gcnew MeasureItemEventHandler( this, &Form1::ComboBox1_MeasureItem
 );
   }

   // If you set the Draw property to DrawMode.OwnerDrawVariable, 
   // you must handle the MeasureItem event. This event handler 
   // will set the height and width of each item before it is drawn.
 
private:
   void ComboBox1_MeasureItem( Object^ sender,
      System::Windows::Forms::MeasureItemEventArgs^ e )
   {
      switch ( e->Index )
      {
         case 0:
            e->ItemHeight = 45;
            break;
         case 1:
            e->ItemHeight = 20;
            break;
         case 2:
            e->ItemHeight = 35;
            break;
      }
      e->ItemWidth = 260;
   }

private:
   // You must handle the DrawItem event for owner-drawn combo boxes. 
 
   // This event handler changes the color, size and font of an 
   // item based on its position in the array.
   void ComboBox1_DrawItem( Object^ sender,
      System::Windows::Forms::DrawItemEventArgs^ e )
   {
      float size = 0;
      System::Drawing::Font^ myFont;
      FontFamily^ family = nullptr;

      System::Drawing::Color animalColor;
      switch ( e->Index )
      {
         case 0:
            size = 30;
            animalColor = System::Drawing::Color::Gray;
            family = FontFamily::GenericSansSerif;
            break;
         case 1:
            size = 10;
            animalColor = System::Drawing::Color::LawnGreen;
            family = FontFamily::GenericMonospace;
            break;
         case 2:
            size = 15;
            animalColor = System::Drawing::Color::Tan;
            family = FontFamily::GenericSansSerif;
            break;
      }

      // Draw the background of the item.
      e->DrawBackground();
      
      // Create a square filled with the animals color. Vary the size
      // of the rectangle based on the length of the animals name.
      Rectangle rectangle = Rectangle( 2, e->Bounds.Top + 2,
         e->Bounds.Height, e->Bounds.Height - 4 );
      e->Graphics->FillRectangle( gcnew SolidBrush( animalColor ), rectangle
 );
      
      // Draw each string in the array, using a different size, color
,
      // and font for each item.
      myFont = gcnew System::Drawing::Font( family, size, FontStyle::Bold );
      e->Graphics->DrawString( animals[ e->Index ], myFont,
         System::Drawing::Brushes::Black, RectangleF(
            e->Bounds.X + rectangle.Width, e->Bounds.Y,
            e->Bounds.Width, e->Bounds.Height) );
      
      // Draw the focus rectangle if the mouse hovers over an item.
      e->DrawFocusRectangle();
   }
System.Windows.Forms.ComboBox comboBox1;

private String animals[];

// This method initializes the owner-drawn combo box.
// The drop-down width is set much wider than the size of the combo
 box
// to accomodate the large items in the list.  The drop-down style is
 set to 
// ComboBox.DropDown, which requires the user to click on the arrow
 to 
// see the list.
private void InitializeComboBox()
{
    this.comboBox1 = new ComboBox();
    this.comboBox1.set_DrawMode(
        System.Windows.Forms.DrawMode.OwnerDrawVariable);
    this.comboBox1.set_Location(new System.Drawing.Point(10,
 20));
    this.comboBox1.set_Name("comboBox1");
    this.comboBox1.set_Size(new System.Drawing.Size(100,
 120));
    this.comboBox1.set_DropDownWidth(250);
    this.comboBox1.set_TabIndex(0);
    this.comboBox1.set_DropDownStyle(ComboBoxStyle.DropDown);
    animals = new String[] { "Elephant", "c r o
 c o d i l e", "lion" };
    comboBox1.set_DataSource(animals);
    this.get_Controls().Add(this.comboBox1);
    // Hook up the MeasureItem and DrawItem events
    this.comboBox1.add_DrawItem(
        new DrawItemEventHandler(comboBox1_DrawItem));
    this.comboBox1.add_MeasureItem(
        new MeasureItemEventHandler(comboBox1_MeasureItem));
} //InitializeComboBox

// If you set the Draw property to DrawMode.OwnerDrawVariable, 
// you must handle the MeasureItem event. This event handler 
// will set the height and width of each item before it is drawn. 
private void comboBox1_MeasureItem(Object sender,
 
    System.Windows.Forms.MeasureItemEventArgs e)
{
    switch (e.get_Index()) {
        case 0:
            e.set_ItemHeight(45);
            break;

        case 1:
            e.set_ItemHeight(20);
            break;

        case 2:
            e.set_ItemHeight(35);
            break;
    }
    e.set_ItemWidth(260);
} //comboBox1_MeasureItem

// You must handle the DrawItem event for owner-drawn combo boxes. 
 
// This event handler changes the color, size and font of an 
// item based on its position in the array.
private void comboBox1_DrawItem(Object sender,
 
    System.Windows.Forms.DrawItemEventArgs e)
{
    float size = 0;
    System.Drawing.Font myFont;
    FontFamily family = null;

    System.Drawing.Color animalColor = new System.Drawing.Color();
    switch (e.get_Index()) {
        case 0:
            size = 30;
            animalColor = System.Drawing.Color.get_Gray();
            family = FontFamily.get_GenericSansSerif();
            break;

        case 1:
            size = 10;
            animalColor = System.Drawing.Color.get_LawnGreen();
            family = FontFamily.get_GenericMonospace();
            break;

        case 2:
            size = 15;
            animalColor = System.Drawing.Color.get_Tan();
            family = FontFamily.get_GenericSansSerif();
            break;
    }
    // Draw the background of the item.
    e.DrawBackground();
    // Create a square filled with the animals color. Vary the size
    // of the rectangle based on the length of the animals name.
    Rectangle rectangle = new Rectangle(2, e.get_Bounds().get_Top()
 + 2, 
        e.get_Bounds().get_Height(),
        e.get_Bounds().get_Height() - 4);
    e.get_Graphics().FillRectangle(new SolidBrush(animalColor),
 rectangle);
    // Draw each string in the array, using a different size, color
,
    // and font for each item.
    myFont = new Font(family, size, FontStyle.Bold);
    e.get_Graphics().DrawString((String)animals.get_Item(e.get_Index()), 
        myFont, System.Drawing.Brushes.get_Black(), 
        new RectangleF(e.get_Bounds().get_X() + rectangle.get_Width()
,
        e.get_Bounds().get_Y(), e.get_Bounds().get_Width(),
        e.get_Bounds().get_Height()));
    // Draw the focus rectangle if the mouse hovers over an item.
    e.DrawFocusRectangle();
} //comboBox1_DrawItem
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

「ComboBox.DrawMode プロパティ」の関連用語

ComboBox.DrawMode プロパティのお隣キーワード
検索ランキング

   

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



ComboBox.DrawMode プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS