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
发布了3 篇原创文章 · 获赞 3 · 访问量 6万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览