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


CheckBoxRenderer クラスには、チェック ボックス コントロールを描画するために使用できる一連の static メソッドが用意されています。コントロールの描画とは、コントロールのユーザー インターフェイスを描画することです。チェック ボックスを描画するには、DrawCheckBox メソッドのうちいずれかを使用します。これらのメソッドにはさまざまなオプションが用意されており、チェック ボックスと共にテキストやイメージを描画できます。
オペレーティング システムで visual スタイルが有効にされており、現在のアプリケーションに visual スタイルが適用されている場合、 DrawCheckBox は現在の visual スタイルでチェック ボックスを描画します。それ以外の場合は、DrawCheckBox はクラシック Windows スタイルでチェック ボックスを描画します。この機能は、描画するカスタム コントロールをオペレーティング システムの現在の visual スタイル設定に自動的に一致させる必要がある場合に便利です。
このクラスは、System.Windows.Forms.VisualStyles.VisualStyleElement.Button.CheckBox クラスが公開する要素のいずれかに設定された System.Windows.Forms.VisualStyles.VisualStyleRenderer の機能をラップします。詳細については、「visual スタイルが使用されているコントロールのレンダリング」を参照してください。
Windows XP Home Edition, Windows XP Professional x64 Edition, Windows Server 2003 プラットフォームメモ : visual スタイルは、これらのプラットフォームでのみサポートされます。

次のコード例では、DrawCheckBox メソッドを使用するカスタム コントロールを記述することによって、マウス クリックに応答するチェック ボックスを描画する方法を示します。
Imports System Imports System.Drawing Imports System.Windows.Forms Imports System.Windows.Forms.VisualStyles Namespace CheckBoxRendererSample Class Form1 Inherits Form Public Sub New() Dim CheckBox1 As New CustomCheckBox() Controls.Add(CheckBox1) If Application.RenderWithVisualStyles Then Me.Text = "Visual Styles Enabled" Else Me.Text = "Visual Styles Disabled" End If End Sub <STAThread()> _ Shared Sub Main() ' If you do not call EnableVisualStyles below, then ' CheckBoxRenderer.DrawCheckBox automatically detects ' this and draws the check box without visual styles. Application.EnableVisualStyles() Application.Run(New Form1()) End Sub End Class Public Class CustomCheckBox Inherits Control Private textRectangleValue As New Rectangle() Private clickedLocationValue As New Point() Private clicked As Boolean = False Private state As CheckBoxState = CheckBoxState.UncheckedNormal Public Sub New() With Me .Location = New Point(50, 50) .Size = New Size(100, 20) .Text = "Click here" .Font = SystemFonts.IconTitleFont End With End Sub ' Calculate the text bounds, exluding the check box. Public ReadOnly Property TextRectangle() As Rectangle Get Using g As Graphics = Me.CreateGraphics() With textRectangleValue .X = Me.ClientRectangle.X + _ CheckBoxRenderer.GetGlyphSize(g, _ CheckBoxState.UncheckedNormal).Width .Y = Me.ClientRectangle.Y .Width = Me.ClientRectangle.Width - _ CheckBoxRenderer.GetGlyphSize(g, _ CheckBoxState.UncheckedNormal).Width .Height = Me.ClientRectangle.Height End With End Using Return textRectangleValue End Get End Property ' Draw the check box in the current state. Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) MyBase.OnPaint(e) CheckBoxRenderer.DrawCheckBox(e.Graphics, _ Me.ClientRectangle.Location, TextRectangle, Me.Text, _ Me.Font, TextFormatFlags.HorizontalCenter, _ clicked, state) End Sub ' Draw the check box in the checked or unchecked state, alternately. Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs) MyBase.OnMouseDown(e) If Not clicked Then With Me .clicked = True .Text = "Clicked!" .state = CheckBoxState.CheckedPressed End With Invalidate() Else With Me .clicked = False .Text = "Click here" .state = CheckBoxState.UncheckedNormal End With Invalidate() End If End Sub ' Draw the check box in the hot state. Protected Overrides Sub OnMouseHover(ByVal e As EventArgs) MyBase.OnMouseHover(e) If clicked Then state = CheckBoxState.CheckedHot Else state = CheckBoxState.UncheckedHot End If Invalidate() End Sub ' Draw the check box in the hot state. Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs) MyBase.OnMouseUp(e) Me.OnMouseHover(e) End Sub ' Draw the check box in the unpressed state. Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs) MyBase.OnMouseLeave(e) If clicked Then state = CheckBoxState.CheckedNormal Else state = CheckBoxState.UncheckedNormal End If Invalidate() End Sub End Class End Namespace
using System; using System.Drawing; using System.Windows.Forms; using System.Windows.Forms.VisualStyles; namespace CheckBoxRendererSample { class Form1 : Form { public Form1() : base() { CustomCheckBox CheckBox1 = new CustomCheckBox(); Controls.Add(CheckBox1); if (Application.RenderWithVisualStyles) this.Text = "Visual Styles Enabled"; else this.Text = "Visual Styles Disabled"; } [STAThread] static void Main() { // If you do not call EnableVisualStyles below, then // CheckBoxRenderer.DrawCheckBox automatically detects // this and draws the check box without visual styles. Application.EnableVisualStyles(); Application.Run(new Form1()); } } public class CustomCheckBox : Control { private Rectangle textRectangleValue = new Rectangle(); private Point clickedLocationValue = new Point(); private bool clicked = false; private CheckBoxState state = CheckBoxState.UncheckedNormal; public CustomCheckBox() : base() { this.Location = new Point(50, 50); this.Size = new Size(100, 20); this.Text = "Click here"; this.Font = SystemFonts.IconTitleFont; } // Calculate the text bounds, exluding the check box. public Rectangle TextRectangle { get { using (Graphics g = this.CreateGraphics()) { textRectangleValue.X = ClientRectangle.X + CheckBoxRenderer.GetGlyphSize(g, CheckBoxState.UncheckedNormal).Width; textRectangleValue.Y = ClientRectangle.Y; textRectangleValue.Width = ClientRectangle.Width - CheckBoxRenderer.GetGlyphSize(g, CheckBoxState.UncheckedNormal).Width; textRectangleValue.Height = ClientRectangle.Height; } return textRectangleValue; } } // Draw the check box in the current state. protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); CheckBoxRenderer.DrawCheckBox(e.Graphics, ClientRectangle.Location, TextRectangle, this.Text , this.Font, TextFormatFlags.HorizontalCenter, clicked, state); } // Draw the check box in the checked or unchecked state, alternately. protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (!clicked) { clicked = true; this.Text = "Clicked!"; state = CheckBoxState.CheckedPressed; Invalidate(); } else { clicked = false; this.Text = "Click here"; state = CheckBoxState.UncheckedNormal; Invalidate(); } } // Draw the check box in the hot state. protected override void OnMouseHover(EventArgs e) { base.OnMouseHover(e); state = clicked ? CheckBoxState.CheckedHot : CheckBoxState.UncheckedHot; Invalidate(); } // Draw the check box in the hot state. protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); this.OnMouseHover(e); } // Draw the check box in the unpressed state. protected override void OnMouseLeave(EventArgs e) { base.OnMouseLeave(e); state = clicked ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal; 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.Windows.Forms.CheckBoxRenderer


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


CheckBoxRenderer メンバ
System.Windows.Forms 名前空間
Application.EnableVisualStyles
Application.RenderWithVisualStyles プロパティ
System.Windows.Forms.VisualStyles.VisualStyleRenderer
System.Windows.Forms.VisualStyles.VisualStyleElement
CheckBoxRenderer プロパティ


関連項目
CheckBoxRenderer クラスSystem.Windows.Forms 名前空間
Application.EnableVisualStyles
Application.RenderWithVisualStyles プロパティ
System.Windows.Forms.VisualStyles.VisualStyleRenderer
System.Windows.Forms.VisualStyles.VisualStyleElement
CheckBoxRenderer メソッド

名前 | 説明 | |
---|---|---|
![]() | DrawCheckBox | オーバーロードされます。 チェック ボックス コントロールを描画します。 |
![]() | DrawParentBackground | 指定した領域にコントロールの親の背景を描画します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetGlyphSize | チェック ボックスのグリフのサイズを返します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | IsBackgroundPartiallyTransparent | チェック ボックスの背景の一部が半透明である (アルファ ブレンドされている) かどうかを示します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

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

関連項目
CheckBoxRenderer クラスSystem.Windows.Forms 名前空間
Application.EnableVisualStyles
Application.RenderWithVisualStyles プロパティ
System.Windows.Forms.VisualStyles.VisualStyleRenderer
System.Windows.Forms.VisualStyles.VisualStyleElement
CheckBoxRenderer メンバ
visual スタイルを使用して、または使用せずに、チェック ボックス コントロールを描画するメソッドを用意します。このクラスは継承できません。
CheckBoxRenderer データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | DrawCheckBox | オーバーロードされます。 チェック ボックス コントロールを描画します。 |
![]() | DrawParentBackground | 指定した領域にコントロールの親の背景を描画します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetGlyphSize | チェック ボックスのグリフのサイズを返します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | IsBackgroundPartiallyTransparent | チェック ボックスの背景の一部が半透明である (アルファ ブレンドされている) かどうかを示します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

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

関連項目
CheckBoxRenderer クラスSystem.Windows.Forms 名前空間
Application.EnableVisualStyles
Application.RenderWithVisualStyles プロパティ
System.Windows.Forms.VisualStyles.VisualStyleRenderer
System.Windows.Forms.VisualStyles.VisualStyleElement
- CheckBoxRendererのページへのリンク