RadioButton 类

RadioButton 类

当与其他 RadioButton 控件成对出现时,使用户能够从一组选项中选择一个选项。

 

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

RadioButton 控件可以显示文本、Image 或同时显示两者。

当用户选择一个组内的一个选项按钮(也称作单选按钮)时,其他选项按钮自动清除。给定容器(如 Form)中的所有 RadioButton 控件构成一个组。若要在一个窗体上创建多个组,请将每个组放在它自己的容器(例如 GroupBoxPanel 控件)中。

RadioButtonCheckBox 控件的功能相似:它们提供用户可以选择或清除的选项。不同之处在于,可以同时选定多个 CheckBox 控件,而选项按钮却是互相排斥的。

使用 Checked 属性可以获取或设置 RadioButton 的状态。通过设置 Appearance 属性,可以将选项按钮的外观显示为切换式按钮或标准选项按钮。

下面的代码示例创建并初始化 GroupBox 中的两个 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


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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值