System.Windows.Forms 名前空間


.NET Framework クラス ライブラリ
RadioButton クラス

更新 : 2007 年 11 月

他の RadioButton コントロールと組み合わせることで、ユーザーは選択肢のグループから 1 つの選択肢を選ぶことができます。

名前空間 :  System.Windows.Forms
アセンブリ :  System.Windows.Forms (System.Windows.Forms.dll 内)

構文

Visual Basic (宣言)
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
<DefaultBindingPropertyAttribute("Checked")> _
Public Class RadioButton _
    Inherits ButtonBase
Visual Basic (使用法)
Dim instance As RadioButton
C#
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[DefaultBindingPropertyAttribute("Checked")]
public class RadioButton : ButtonBase
Visual C++
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)]
[DefaultBindingPropertyAttribute(L"Checked")]
public ref class RadioButton : public ButtonBase
J#
/** @attribute ComVisibleAttribute(true) */
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */
/** @attribute DefaultBindingPropertyAttribute("Checked") */
public class RadioButton extends ButtonBase
JScript
public class RadioButton extends ButtonBase
解説

RadioButton コントロールには、テキストおよび Image、またはその両方を表示できます。

ユーザーがグループ内のオプション ボタンの 1 つを選択すると、他のボタンは自動的にオフになります。特定のコンテナ内にある Form などのすべての RadioButton コントロールは、1 つのグループとなります。1 つのフォーム上に複数のグループを作成する場合は、グループを GroupBox コントロールや Panel コントロールなどの独自のコンテナに配置します。

RadioButton コントロールと CheckBox コントロールには似た機能があり、ユーザーが選択または選択解除できる選択肢を表示します。相違点は、CheckBox コントロールが同時に複数選択できるのに対して、オプション ボタンは一度に 1 つしか選択できない点です。

Checked プロパティを使用して、RadioButton の状態を取得または設定します。オプション ボタンの外観は、Appearance プロパティを設定して変更でき、トグル スタイルのボタンまたは標準のオプション ボタンで表示できます。


GroupBox に 2 つの RadioButton コントロールを作成して初期化するコード例を次に示します。この例を実行するには、コードを Windows フォームに貼り付けます。次に、フォームのコンストラクタまたは Load イベント処理メソッドで InitializeRadioButtons を呼び出します。

Visual Basic
Private groupBox1 As GroupBox
Private radioButton2 As RadioButton
Private radioButton1 As RadioButton


Public Sub InitializeRadioButtons() 
    Me.groupBox1 = New System.Windows.Forms.GroupBox()
    Me.radioButton2 = New System.Windows.Forms.RadioButton()
    Me.radioButton1 = New System.Windows.Forms.RadioButton()

    Me.groupBox1.Controls.Add(Me.radioButton2)
    Me.groupBox1.Controls.Add(Me.radioButton1)
    Me.groupBox1.Location = New System.Drawing.Point(80, 75)
    Me.groupBox1.Size = New System.Drawing.Size(200, 100)
    Me.groupBox1.Text = "Radio Buttons"

    Me.radioButton2.Location = New System.Drawing.Point(31, 53)
    Me.radioButton2.Size = New System.Drawing.Size(67, 17)
    Me.radioButton2.Text = "Choice 2"

    Me.radioButton1.Location = New System.Drawing.Point(31, 20)
    Me.radioButton1.Name = "radioButton1"
    Me.radioButton1.Size = New System.Drawing.Size(67, 17)
    Me.radioButton1.Text = "Choice 1"

    Me.ClientSize = New System.Drawing.Size(292, 266)
    Me.Controls.Add(Me.groupBox1)

End Sub

C#
private GroupBox groupBox1;
private RadioButton radioButton2;
private RadioButton radioButton1;

public void InitializeRadioButtons()
{
    this.groupBox1 = new System.Windows.Forms.GroupBox();
    this.radioButton2 = new System.Windows.Forms.RadioButton();
    this.radioButton1 = new System.Windows.Forms.RadioButton();

    this.groupBox1.Controls.Add(this.radioButton2);
    this.groupBox1.Controls.Add(this.radioButton1);
    this.groupBox1.Location = new System.Drawing.Point(80, 75);
    this.groupBox1.Size = new System.Drawing.Size(200, 100);
    this.groupBox1.Text = "Radio Buttons";

    this.radioButton2.Location = new System.Drawing.Point(31, 53);
    this.radioButton2.Size = new System.Drawing.Size(67, 17);
    this.radioButton2.Text = "Choice 2";

    this.radioButton1.Location = new System.Drawing.Point(31, 20);
    this.radioButton1.Name = "radioButton1";
    this.radioButton1.Size = new System.Drawing.Size(67, 17);
    this.radioButton1.Text = "Choice 1";

    this.ClientSize = new System.Drawing.Size(292, 266);
    this.Controls.Add(this.groupBox1);
}
継承階層

System..::.Object
  System..::.MarshalByRefObject
    System.ComponentModel..::.Component
      System.Windows.Forms..::.Control
        System.Windows.Forms..::.ButtonBase
          System.Windows.Forms..::.RadioButton
スレッド セーフ

この型のすべてのパブリック static (Visual Basic では Shared) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォーム

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Pocket PC

.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 3.5、3.0、2.0、1.1、1.0

.NET Compact Framework

サポート対象 : 3.5、2.0、1.0
参照

参照

タグ :


Page view tracker