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


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

DrawRadioButton メソッドを使用して、マウスのクリックに応答するオプション ボタンを描画するカスタム コントロールを作成する方法を次のコード例に示します。
Imports System Imports System.Drawing Imports System.Windows.Forms Imports System.Windows.Forms.VisualStyles Namespace RadioButtonRendererSample Class Form1 Inherits Form Dim WithEvents button1 As Button Public Sub New() Dim RadioButton1 As New CustomRadioButton() button1 = New Button Me.button1.Location = New System.Drawing.Point(185, 231) Me.button1.Size = New System.Drawing.Size(105, 23) Me.button1.Text = "Toggle Styles" Controls.Add(RadioButton1) Controls.Add(button1) 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 ' RadioButtonRenderer.DrawRadioButton automatically detects ' this and draws the radio button without visual styles. Application.EnableVisualStyles() Application.Run(New Form1()) End Sub ' Match application style and toggle visual styles off ' and on for the application. Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) _ Handles button1.Click RadioButtonRenderer.RenderMatchingApplicationState = True Application.VisualStyleState = _ Application.VisualStyleState Xor _ VisualStyleState.ClientAndNonClientAreasEnabled If Application.RenderWithVisualStyles Then Me.Text = "Visual Styles Enabled" Else Me.Text = "Visual Styles Disabled" End If End Sub End Class Public Class CustomRadioButton Inherits Control Private textRectangleValue As New Rectangle() Private clicked As Boolean = False Private state As RadioButtonState = RadioButtonState.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 'New ' Define the text bounds so that the text rectangle ' does not include the radio button. Public ReadOnly Property TextRectangle() As Rectangle Get Using g As Graphics = Me.CreateGraphics() With textRectangleValue .X = Me.ClientRectangle.X + _ RadioButtonRenderer.GetGlyphSize(g, _ RadioButtonState.UncheckedNormal).Width .Y = Me.ClientRectangle.Y .Width = Me.ClientRectangle.Width - _ RadioButtonRenderer.GetGlyphSize(g, _ RadioButtonState.UncheckedNormal).Width .Height = Me.ClientRectangle.Height End With End Using Return textRectangleValue End Get End Property ' Draw the radio button in the current state. Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) MyBase.OnPaint(e) RadioButtonRenderer.DrawRadioButton(e.Graphics, _ Me.ClientRectangle.Location, TextRectangle, Me.Text, _ Me.Font, clicked, state) End Sub ' Draw the radio button in the checked or unchecked state. Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs) MyBase.OnMouseDown(e) If Not clicked Then clicked = True Me.Text = "Clicked!" state = RadioButtonState.CheckedPressed Invalidate() Else clicked = False Me.Text = "Click here" state = RadioButtonState.UncheckedNormal Invalidate() End If End Sub ' Draw the radio button in the hot state. Protected Overrides Sub OnMouseHover(ByVal e As EventArgs) MyBase.OnMouseHover(e) If clicked Then state = RadioButtonState.CheckedHot Else state = RadioButtonState.UncheckedHot End If Invalidate() End Sub ' Draw the radio button in the hot state. Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs) MyBase.OnMouseUp(e) Me.OnMouseHover(e) End Sub ' Draw the radio button in the unpressed state. Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs) MyBase.OnMouseLeave(e) If clicked Then state = RadioButtonState.CheckedNormal Else state = RadioButtonState.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 RadioButtonRendererSample { class Form1 : Form { Button button1 = new Button(); public Form1() : base() { CustomRadioButton RadioButton1 = new CustomRadioButton(); button1.Location = new System.Drawing.Point(175, 231); button1.Size = new System.Drawing.Size(105, 23); button1.Text = "Toggle Style"; button1.Click += new System.EventHandler(this.button1_Click); Controls.Add(RadioButton1); Controls.Add(button1); 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 // RadioButtonRenderer.DrawRadioButton automatically detects // this and draws the radio button without visual styles. Application.EnableVisualStyles(); Application.Run(new Form1()); } private void button1_Click(object sender, EventArgs e) { Application.VisualStyleState = Application.VisualStyleState ^ VisualStyleState.ClientAndNonClientAreasEnabled; GroupBoxRenderer.RenderMatchingApplicationState = true; if (Application.RenderWithVisualStyles) this.Text = "Visual Styles Enabled"; else this.Text = "Visual Styles Disabled"; } } public class CustomRadioButton : Control { private Rectangle textRectangleValue = new Rectangle(); private bool clicked = false; private RadioButtonState state = RadioButtonState.UncheckedNormal; public CustomRadioButton() : base() { this.Location = new Point(50, 50); this.Size = new Size(100, 20); this.Text = "Click here"; this.Font = SystemFonts.IconTitleFont; } // Define the text bounds so that the text rectangle // does not include the radio button. public Rectangle TextRectangle { get { using (Graphics g = this.CreateGraphics()) { textRectangleValue.X = ClientRectangle.X + RadioButtonRenderer.GetGlyphSize(g, RadioButtonState.UncheckedNormal).Width; textRectangleValue.Y = ClientRectangle.Y; textRectangleValue.Width = ClientRectangle.Width - RadioButtonRenderer.GetGlyphSize(g, RadioButtonState.UncheckedNormal).Width; textRectangleValue.Height = ClientRectangle.Height; } return textRectangleValue; } } // Draw the radio button in the current state. protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); RadioButtonRenderer.DrawRadioButton(e.Graphics, ClientRectangle.Location, TextRectangle, this.Text , this.Font, clicked, state); } // Draw the radio button in the checked or unchecked state. protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (!clicked) { clicked = true; this.Text = "Clicked!"; state = RadioButtonState.CheckedPressed; Invalidate(); } else { clicked = false; this.Text = "Click here"; state = RadioButtonState.UncheckedNormal; Invalidate(); } } // Draw the radio button in the hot state. protected override void OnMouseHover(EventArgs e) { base.OnMouseHover(e); state = clicked ? RadioButtonState.CheckedHot : RadioButtonState.UncheckedHot; Invalidate(); } // Draw the radio button in the hot state. protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); this.OnMouseHover(e); } // Draw the radio button in the unpressed state. protected override void OnMouseLeave(EventArgs e) { base.OnMouseLeave(e); state = clicked ? RadioButtonState.CheckedNormal : RadioButtonState.UncheckedNormal; Invalidate(); } } }
#using <System.Drawing.dll> #using <System.Windows.Forms.dll> #using <System.dll> using namespace System; using namespace System::Drawing; using namespace System::Windows::Forms; using namespace System::Windows::Forms::VisualStyles; namespace RadioButtonRendererSample { public ref class CustomRadioButton : public Control { private: Rectangle textRectangleValue; private: bool clicked; private: RadioButtonState state; public: CustomRadioButton() : Control() { textRectangleValue = Rectangle(); state = RadioButtonState::UncheckedNormal; this->Location = Point(50, 50); this->Size = System::Drawing::Size(100, 20); this->Text = "Click here"; this->Font = SystemFonts::IconTitleFont; } // Define the text bounds so that the text rectangle // does not include the radio button. public: property Rectangle TextRectangle { Rectangle get() { Graphics^ g = this->CreateGraphics(); textRectangleValue.X = ClientRectangle.X + RadioButtonRenderer::GetGlyphSize(g, RadioButtonState::UncheckedNormal).Width; textRectangleValue.Y = ClientRectangle.Y; textRectangleValue.Width = ClientRectangle.Width - RadioButtonRenderer::GetGlyphSize(g, RadioButtonState::UncheckedNormal).Width; textRectangleValue.Height = ClientRectangle.Height; delete g; return textRectangleValue; } } // Draw the radio button in the current state. protected: virtual void OnPaint(PaintEventArgs^ e) override { __super::OnPaint(e); RadioButtonRenderer::DrawRadioButton(e->Graphics, ClientRectangle.Location, TextRectangle, this->Text , this->Font, clicked, state); } // Draw the radio button in the checked or unchecked state. protected: virtual void OnMouseDown(MouseEventArgs^ e) override { __super::OnMouseDown(e); if (!clicked) { clicked = true; this->Text = "Clicked!"; state = RadioButtonState::CheckedPressed; Invalidate(); } else { clicked = false; this->Text = "Click here"; state = RadioButtonState::UncheckedNormal; Invalidate(); } } // Draw the radio button in the hot state. protected: virtual void OnMouseHover(EventArgs^ e) override { __super::OnMouseHover(e); state = clicked ? RadioButtonState::CheckedHot : RadioButtonState::UncheckedHot; Invalidate(); } // Draw the radio button in the hot state. protected: virtual void OnMouseUp(MouseEventArgs^ e) override { __super::OnMouseUp(e); this->OnMouseHover(e); } // Draw the radio button in the normal (i.e. not hot) state protected: virtual void OnMouseLeave(EventArgs^ e) override { __super::OnMouseLeave(e); state = clicked ? RadioButtonState::CheckedNormal : RadioButtonState::UncheckedNormal; Invalidate(); } }; public ref class Form1 : public Form { public: Form1() : Form() { Controls->Add(gcnew CustomRadioButton()); if (Application::RenderWithVisualStyles) { this->Text = "Visual Styles Enabled"; } else { this->Text = "Visual Styles Disabled"; } } }; } [STAThread] int main() { // If you do not call EnableVisualStyles below, then // RadioButtonRenderer.DrawRadioButton automatically detects // this and draws the radio button without visual styles. Application::EnableVisualStyles(); Application::Run(gcnew RadioButtonRendererSample::Form1()); }

System.Windows.Forms.RadioButtonRenderer


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


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


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

名前 | 説明 | |
---|---|---|
![]() | DrawParentBackground | 指定領域にコントロールの親の背景を描画します。 |
![]() | DrawRadioButton | オーバーロードされます。 オプション ボタン コントロールを描画します。 |
![]() | 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 から継承されます。) |

関連項目
RadioButtonRenderer クラスSystem.Windows.Forms 名前空間
Application.EnableVisualStyles
Application.VisualStyleState プロパティ
System.Windows.Forms.VisualStyles.VisualStyleRenderer
System.Windows.Forms.VisualStyles.VisualStyleElement
RadioButtonRenderer メンバ
visual スタイルを使用して (または使用せずに) オプション ボタン コントロールをレンダリングするために使用されるメソッドを提供します。このクラスは継承できません。
RadioButtonRenderer データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | DrawParentBackground | 指定領域にコントロールの親の背景を描画します。 |
![]() | DrawRadioButton | オーバーロードされます。 オプション ボタン コントロールを描画します。 |
![]() | 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 から継承されます。) |

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