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

ComboBoxRenderer クラス

メモ : このクラスは、.NET Framework version 2.0 で新しく追加されたものです。

visual スタイルを使用してコンボ ボックス コントロールを描画するメソッドを用意します。このクラスは継承できません。

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

Public NotInheritable Class
 ComboBoxRenderer
Dim instance As ComboBoxRenderer
public sealed class ComboBoxRenderer
public ref class ComboBoxRenderer sealed
public final class ComboBoxRenderer
public final class ComboBoxRenderer
解説解説

ComboBoxRenderer クラスには、オペレーティング システムの現在の visual スタイルを使用してコンボ ボックス コントロールを描画するために使用できる、一連の static メソッドが用意されています。コントロールの描画とは、コントロールのユーザー インターフェイスを描画することです。これは、現在の visual スタイルの外観を持つカスタム コントロールを描画する場合に役立ちます。コンボ ボックスを描画するには、DrawTextBox メソッドを使用してテキスト ボックスを描画し、DrawDropDownButton メソッドを使用してドロップダウン矢印を描画します。

オペレーティング システムで visual スタイルが有効にされており、visual スタイルがアプリケーション ウィンドウのクライアント領域に適用されている場合、DrawTextBox および DrawDropDownButton は、現在の visual スタイルを使用してコンボ ボックスを描画します。それ以外の場合は、これらのメソッドは InvalidOperationException をスローします。このクラスのメンバを使用できるかどうかを判断するには、IsSupported プロパティの値を確認します。

このクラスは、System.Windows.Forms.VisualStyles.VisualStyleElement.ComboBox.DropDownButton クラスと System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox.TextEdit クラスが公開する要素のうちいずれかに設定されている System.Windows.Forms.VisualStyles.VisualStyleRenderer の機能をラップします。詳細については、「visual スタイルが使用されているコントロールのレンダリング」を参照してください。

Windows XP Home Edition, Windows XP Professional x64 Edition, Windows Server 2003 プラットフォームメモ : visual スタイルは、これらのプラットフォームでのみサポートされます。

使用例使用例

DrawTextBox メソッドと DrawDropDownButton メソッドを使用するカスタム コントロールを作成することによって、マウス クリックに応答するコンボ ボックスを描画する方法を、次のコード例に示します。

Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Windows.Forms.VisualStyles

Namespace ComboBoxRendererSample
    Class Form1
        Inherits Form

        Public Sub New()
            Me.Size = New Size(300, 300)
            Dim ComboBox1 As New
 CustomComboBox()
            Controls.Add(ComboBox1)
        End Sub

        <STAThread()> _
        Shared Sub Main()
            ' The call to EnableVisualStyles below does not affect
            ' whether ComboBoxRenderer.IsSupported is true; as long
 as visual
            ' styles are enabled by the operating system, IsSupported
 is true.
            Application.EnableVisualStyles()
            Application.Run(New Form1())
        End Sub
    End Class

    Public Class CustomComboBox
        Inherits Control

        Private arrowSize As Size
        Private arrowRectangle As Rectangle
        Private topTextBoxRectangle As Rectangle
        Private bottomTextBoxRectangle As Rectangle
        Private textBoxState As ComboBoxState
 = ComboBoxState.Normal
        Private arrowState As ComboBoxState
 = ComboBoxState.Normal
        Private bottomText As String
 = "Using ComboBoxRenderer"
        Private isActivated As Boolean
 = False
        Private minHeight As Integer
 = 38
        Private minWidth As Integer
 = 40

        Public Sub New()
            Me.Location = New Point(10, 10)
            Me.Size = New Size(140, 38)
            Me.Font = SystemFonts.IconTitleFont
            Me.Text = "Click the button"

            ' Initialize the rectangles to look like the standard combo
 
            ' box control.
            arrowSize = New Size(18, 20)
            arrowRectangle = New Rectangle(Me.ClientRectangle.X
 + _
                Me.ClientRectangle.Width - arrowSize.Width - 1,
 _
                Me.ClientRectangle.Y + 1, arrowSize.Width, _
                arrowSize.Height)
            topTextBoxRectangle = New Rectangle(Me.ClientRectangle.X,
 _
                Me.ClientRectangle.Y, Me.ClientRectangle.Width,
 _
                arrowSize.Height + 2)
            bottomTextBoxRectangle = New Rectangle(Me.ClientRectangle.X,
 _
                Me.ClientRectangle.Y + topTextBoxRectangle.Height,
 _
                Me.ClientRectangle.Width, topTextBoxRectangle.Height
 - 6)
        End Sub

        ' Draw the combo box in the current state.
        Protected Overrides Sub
 OnPaint(ByVal e As PaintEventArgs)
            MyBase.OnPaint(e)

            If Not ComboBoxRenderer.IsSupported
 Then
                Me.Parent.Text = "Visual Styles
    Disabled"
                Return
            End If

            Me.Parent.Text = "CustomComboBox
 Enabled"

            ' Always draw the main text box and drop down arrow in their
 
            ' current states.
            ComboBoxRenderer.DrawTextBox(e.Graphics, topTextBoxRectangle, _
                Me.Text, Me.Font, textBoxState)
            ComboBoxRenderer.DrawDropDownButton(e.Graphics, arrowRectangle, _
                arrowState)

            ' Only draw the bottom text box if the arrow has been clicked.
            If isActivated Then
                ComboBoxRenderer.DrawTextBox(e.Graphics, _
                    bottomTextBoxRectangle, bottomText, Me.Font,
 textBoxState)
            End If
        End Sub

        Protected Overrides Sub
 OnMouseDown(ByVal e As MouseEventArgs)
            MyBase.OnMouseDown(e)

            ' Check whether the user clicked the arrow.
            If arrowRectangle.Contains(e.Location) And
 _
                ComboBoxRenderer.IsSupported Then

                ' Draw the arrow in the pressed state.
                arrowState = ComboBoxState.Pressed

                ' The user has activated the combo box.
                If Not isActivated Then
                    Me.Text = "Clicked!"
                    textBoxState = ComboBoxState.Pressed
                    isActivated = True

                ' The user has deactivated the combo box.
                Else
                    Me.Text = "Click here"
                    textBoxState = ComboBoxState.Normal
                    isActivated = False
                End If

                ' Redraw the control.
                Invalidate()
            End If
        End Sub

        Protected Overrides Sub
 OnMouseUp(ByVal e As MouseEventArgs)
            MyBase.OnMouseUp(e)
            If arrowRectangle.Contains(e.Location) And
 _
                ComboBoxRenderer.IsSupported Then
                arrowState = ComboBoxState.Normal
                Invalidate()
            End If
        End Sub

    End Class
End Namespace
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;

namespace ComboBoxRendererSample
{
    class Form1 : Form
    {
        public Form1()
            : base()
        {
            this.Size = new Size(300, 300);
            CustomComboBox ComboBox1 = new CustomComboBox();
            Controls.Add(ComboBox1);
        }

        [STAThread]
        static void Main()
        {
            // The call to EnableVisualStyles below does not affect
            // whether ComboBoxRenderer.IsSupported is true; as long
 as visual
            // styles are enabled by the operating system, IsSupported
 is true.
            Application.EnableVisualStyles();
            Application.Run(new Form1());
        }
    }

    public class CustomComboBox : Control
    {
        private Size arrowSize;
        private Rectangle arrowRectangle;
        private Rectangle topTextBoxRectangle;
        private Rectangle bottomTextBoxRectangle;
        private ComboBoxState textBoxState = ComboBoxState.Normal;
        private ComboBoxState arrowState = ComboBoxState.Normal;
        private String bottomText = "Using ComboBoxRenderer";
        private bool isActivated = false;
        private const int
 minHeight = 38;
        private const int
 minWidth = 40;

        public CustomComboBox()
            : base()
        {
            this.Location = new Point(10, 10);
            this.Size = new Size(140, 38);
            this.Font = SystemFonts.IconTitleFont;
            this.Text = "Click the button";

            // Initialize the rectangles to look like the standard combo
 
            // box control.
            arrowSize = new Size(18, 20);
            arrowRectangle = new Rectangle(ClientRectangle.X +
                ClientRectangle.Width - arrowSize.Width - 1,
                ClientRectangle.Y + 1,
                arrowSize.Width,
                arrowSize.Height);
            topTextBoxRectangle = new Rectangle(ClientRectangle.X
,
                ClientRectangle.Y,
                ClientRectangle.Width,
                arrowSize.Height + 2);
            bottomTextBoxRectangle = new Rectangle(ClientRectangle.X
,
                ClientRectangle.Y + topTextBoxRectangle.Height,
                ClientRectangle.Width,
                topTextBoxRectangle.Height - 6);
        }

        // Draw the combo box in the current state.
        protected override void OnPaint(PaintEventArgs
 e)
        {
            base.OnPaint(e);

            if (!ComboBoxRenderer.IsSupported)
            {
                this.Parent.Text = "Visual Styles Disabled";
                return;
            }

            this.Parent.Text = "CustomComboBox Enabled";

            // Always draw the main text box and drop down arrow in
 their 
            // current states
            ComboBoxRenderer.DrawTextBox(e.Graphics, topTextBoxRectangle,
                this.Text, this.Font, textBoxState);
            ComboBoxRenderer.DrawDropDownButton(e.Graphics, arrowRectangle,
                arrowState);

            // Only draw the bottom text box if the arrow has been clicked
            if (isActivated)
            {
                ComboBoxRenderer.DrawTextBox(e.Graphics,
                    bottomTextBoxRectangle, bottomText, this.Font
,
                    textBoxState);
            }
        }

        protected override void OnMouseDown(MouseEventArgs
 e)
        {
            base.OnMouseDown(e);

            // Check whether the user clicked the arrow.
            if (arrowRectangle.Contains(e.Location) &&
                ComboBoxRenderer.IsSupported)
            {
                // Draw the arrow in the pressed state.
                arrowState = ComboBoxState.Pressed;

                // The user has activated the combo box.
                if (!isActivated)
                {
                    this.Text = "Clicked!";
                    textBoxState = ComboBoxState.Pressed;
                    isActivated = true;
                }

                // The user has deactivated the combo box.
                else
                {
                    this.Text = "Click here";
                    textBoxState = ComboBoxState.Normal;
                    isActivated = false;
                }

                // Redraw the control.
                Invalidate();
            }
        }

        protected override void OnMouseUp(MouseEventArgs
 e)
        {
            base.OnMouseUp(e);

            if (arrowRectangle.Contains(e.Location) &&
                ComboBoxRenderer.IsSupported)
            {
                arrowState = ComboBoxState.Normal;
                Invalidate();
            }
        }
    }
}
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::Windows::Forms::VisualStyles;

namespace ComboBoxRendererSample
{
    ref class CustomComboBox: public Control
    {
    private:
        System::Drawing::Size arrowSize;
        Rectangle arrowRectangle;
        Rectangle topTextBoxRectangle;
        Rectangle bottomTextBoxRectangle;
        ComboBoxState textBoxState;
        ComboBoxState arrowState;
        String^ bottomText;
        bool isActivated;
        int minHeight;
        int minWidth;

    public:
        CustomComboBox() : Control()

          {
              minHeight = 38;
              minWidth = 40; 
              this->Location = Point(10, 10);
              this->Size = System::Drawing::Size(140, 38);
              this->Font = SystemFonts::IconTitleFont;
              this->Text = "Click the button";
              textBoxState = ComboBoxState::Normal;
              bottomText = "Using ComboBoxRenderer";
              arrowState = ComboBoxState::Normal;

              // Initialize the rectangles to look like the standard
 combo
              // box control.
              arrowSize = System::Drawing::Size(18, 20);
              arrowRectangle = Rectangle(ClientRectangle.X +
                  ClientRectangle.Width - arrowSize.Width - 1,
                  ClientRectangle.Y + 1,
                  arrowSize.Width,
                  arrowSize.Height);
              topTextBoxRectangle = Rectangle(ClientRectangle.X,
                  ClientRectangle.Y,
                  ClientRectangle.Width,
                  arrowSize.Height + 2);
              bottomTextBoxRectangle = Rectangle(ClientRectangle.X,
                  ClientRectangle.Y + topTextBoxRectangle.Height,
                  ClientRectangle.Width,
                  topTextBoxRectangle.Height - 6);
          }

          // Draw the combo box in the current state.
    protected:
        virtual void OnPaint(PaintEventArgs^ e) override 
        {
            Control::OnPaint(e);

            if (!ComboBoxRenderer::IsSupported)
            {
                this->Parent->Text = "Visual Styles
 Disabled";
                return;
            }

            this->Parent->Text = "CustomComboBox Enabled";

            // Always draw the main text box and drop down arrow in
 their
            // current states
            ComboBoxRenderer::DrawTextBox(e->Graphics, topTextBoxRectangle,
                this->Text, this->Font,
 textBoxState);
            ComboBoxRenderer::DrawDropDownButton(e->Graphics, arrowRectangle,
                arrowState);

            // Only draw the bottom text box if the arrow has been clicked
            if (isActivated)
            {
                ComboBoxRenderer::DrawTextBox(e->Graphics,
                    bottomTextBoxRectangle, bottomText, this->Font
,
                    textBoxState);
            }
        }

    protected:
        virtual void OnMouseDown(MouseEventArgs^ e) override 
        {
            Control::OnMouseDown(e);

            // Check whether the user clicked the arrow.
            if (arrowRectangle.Contains(e->Location) &&
                ComboBoxRenderer::IsSupported)
            {
                // Draw the arrow in the pressed state.
                arrowState = ComboBoxState::Pressed;

                // The user has activated the combo box.
                if (!isActivated)
                {
                    this->Text = "Clicked!";
                    textBoxState = ComboBoxState::Pressed;
                    isActivated = true;
                }

                // The user has deactivated the combo box.
                else
                {
                    this->Text = "Click here";
                    textBoxState = ComboBoxState::Normal;
                    isActivated = false;
                }

                // Redraw the control.
                Invalidate();
            }
        }

    protected:
        virtual void OnMouseUp(MouseEventArgs^ e) override 
        {
            Control::OnMouseUp(e);

            if (arrowRectangle.Contains(e->Location) &&
                ComboBoxRenderer::IsSupported)
            {
                arrowState = ComboBoxState::Normal;
                Invalidate();
            }
        }
    };

    ref class Form1 : public Form
    {
    public:
        Form1() : Form()
        {
            this->Size = System::Drawing::Size(300, 300);
            CustomComboBox^ ComboBox1 = gcnew CustomComboBox();
            Controls->Add(ComboBox1);
        }

    };

}

[STAThread]
int main()
{
    // The call to EnableVisualStyles below does not affect
    // whether ComboBoxRenderer.IsSupported is true; as long as visual
    // styles are enabled by the operating system, IsSupported is true.
    Application::EnableVisualStyles();
    Application::Run(gcnew ComboBoxRendererSample::Form1());

}
継承階層継承階層
System.Object
  System.Windows.Forms.ComboBoxRenderer
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ComboBoxRenderer メンバ
System.Windows.Forms 名前空間
System.Windows.Forms.VisualStyles.VisualStyleRenderer
System.Windows.Forms.VisualStyles.VisualStyleElement

ComboBoxRenderer プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ IsSupported visual スタイルを使用してコンボ ボックスを描画するために、ComboBoxRenderer クラスを使用できるかどうかを示す値を取得します。
参照参照

関連項目

ComboBoxRenderer クラス
System.Windows.Forms 名前空間
System.Windows.Forms.VisualStyles.VisualStyleRenderer
System.Windows.Forms.VisualStyles.VisualStyleElement

ComboBoxRenderer メソッド


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

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

関連項目

ComboBoxRenderer クラス
System.Windows.Forms 名前空間
System.Windows.Forms.VisualStyles.VisualStyleRenderer
System.Windows.Forms.VisualStyles.VisualStyleElement

ComboBoxRenderer メンバ

visual スタイルを使用してコンボ ボックス コントロールを描画するメソッドを用意します。このクラスは継承できません。

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


パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ IsSupported visual スタイルを使用してコンボ ボックスを描画するために、ComboBoxRenderer クラスを使用できるかどうかを示す値を取得します。
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

ComboBoxRenderer クラス
System.Windows.Forms 名前空間
System.Windows.Forms.VisualStyles.VisualStyleRenderer
System.Windows.Forms.VisualStyles.VisualStyleElement



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

「ComboBoxRenderer」の関連用語

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

   

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



ComboBoxRendererのページの著作権

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

©2026 GRAS Group, Inc.RSS