ControlCollection.AddRadioButton 方法 (Range, String) (2007 system)

更新:2007 年 11 月

在工作表中的指定范围添加一个新的 RadioButton 控件。

命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel.v9.0(在 Microsoft.Office.Tools.Excel.v9.0.dll 中)

语法

声明
Public Function AddRadioButton ( _
    range As Range, _
    name As String _
) As RadioButton
用法
Dim instance As ControlCollection
Dim range As Range
Dim name As String
Dim returnValue As RadioButton

returnValue = instance.AddRadioButton(range, _
    name)
public RadioButton AddRadioButton(
    Range range,
    string name
)

参数

返回值

类型:Microsoft.Office.Tools.Excel.Controls.RadioButton

添加到 ControlCollection 实例的 RadioButton 控件。

异常

异常 条件
ArgumentNullException

名称参数或范围参数为 nullnull 引用(在 Visual Basic 中为 Nothing),或者名称参数长度为零。

ControlNameAlreadyExistsException

ControlCollection 实例中已存在一个同名控件。

InvalidRangeException

指定的范围无效。不能使用多区域范围。该范围应与 ControlCollection 实例同在一个工作表中。

备注

使用 AddRadioButton 方法可以将 RadioButton 对象添加到 ControlCollection 的末尾。若要移除以前以编程方式添加的 RadioButton,请使用 Remove() 方法。

在调整范围的大小时,控件会自动调整其自身的大小。

如果直接将多个单选按钮添加到文档中,这些单选按钮并不是互相排斥的。您可以编写代码使单选按钮互相排斥;但是,首选方法是将单选按钮添加到一个用户控件,然后将此用户控件添加到文档。

示例

下面的代码示例将两个 RadioButton 控件添加到工作表的单元格“A1”和“A2”中,然后为每个控件指定文本。

Private Sub ExcelRangeAddRadioButton()

    Dim RadioButton1 As Microsoft.Office.Tools. _
        Excel.Controls.RadioButton = Me.Controls. _
        AddRadioButton(Me.Range("A1"), "RadioButton1")
    Dim RadioButton2 As Microsoft.Office.Tools. _
        Excel.Controls.RadioButton = Me.Controls. _
        AddRadioButton(Me.Range("A2"), "RadioButton2")

    RadioButton1.Text = "Bold"
    RadioButton2.Text = "Italic"
    RadioButton2.Checked = False

End Sub

private void ExcelRangeAddRadioButton()
{


    Microsoft.Office.Tools.Excel.Controls.RadioButton
         radioButton1 = this.Controls.AddRadioButton(
         this.Range["A1", missing], "radioButton1");
    Microsoft.Office.Tools.Excel.Controls.RadioButton
         radioButton2 = this.Controls.AddRadioButton(
         this.Range["A2", missing], "radioButton2");
    radioButton1.Text = "Bold";
    radioButton2.Text = "Italic";
    radioButton2.Checked = false;

}

权限

另请参见

参考

ControlCollection 类

ControlCollection 成员

AddRadioButton 重载

Microsoft.Office.Tools.Excel 命名空间