ControlExtensions.AddRadioButton 方法 (ControlCollection, Double, Double, Double, Double, String)

按照指定的大小和位置向工作表添加一个新的 RadioButton 控件。

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

语法

声明
<ExtensionAttribute> _
Public Shared Function AddRadioButton ( _
    controls As ControlCollection, _
    left As Double, _
    top As Double, _
    width As Double, _
    height As Double, _
    name As String _
) As RadioButton
public static RadioButton AddRadioButton(
    this ControlCollection controls,
    double left,
    double top,
    double width,
    double height,
    string name
)

参数

  • left
    类型:System.Double
    控件左边缘与工作表左边缘之间的距离(以磅为单位)。
  • top
    类型:System.Double
    控件上边缘与工作表上边缘之间的距离(以磅为单位)。
  • width
    类型:System.Double
    控件的宽度(以磅为单位)。
  • height
    类型:System.Double
    控件的高度(以磅为单位)。

返回值

类型:Microsoft.Office.Tools.Excel.Controls.RadioButton
添加到 ControlCollection 实例的 RadioButton 控件。

使用说明

在 Visual Basic 和 C# 中,可以在 ControlCollection 类型的任何对象上将此方法作为实例方法来调用。当使用实例方法语法调用此方法时,请省略第一个参数。有关更多信息,请参见扩展方法 (Visual Basic)扩展方法(C# 编程指南)

异常

异常 条件
ArgumentNullException

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

ControlNameAlreadyExistsException

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

备注

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

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

示例

下面的代码示例将两个 RadioButton 控件添加到工作表顶端,然后为每个控件指定文本。 若要使用此示例,请从文档级项目内的 Sheet1 类中运行此示例。

    Private Sub ExcelAddRadioButton()

        Dim RadioButton1 As Microsoft.Office.Tools. _
            Excel.Controls.RadioButton = Me.Controls. _
            AddRadioButton(0, 0, 78, 18, "RadioButton1")
        Dim RadioButton2 As Microsoft.Office.Tools. _
            Excel.Controls.RadioButton = Me.Controls. _
            AddRadioButton(0, 18, 78, 18, "RadioButton2")

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

    End Sub

private void ExcelAddRadioButton()
{

    Microsoft.Office.Tools.Excel.Controls.RadioButton
         radioButton1 = this.Controls.AddRadioButton(
         0, 0, 78, 18, "radioButton1");
    Microsoft.Office.Tools.Excel.Controls.RadioButton
         radioButton2 = this.Controls.AddRadioButton(
         0, 18, 78, 18, "radioButton2");
    radioButton1.Text = "Bold";
    radioButton2.Text = "Italic";
    radioButton2.Checked = false;
}

.NET Framework 安全性

请参见

参考

ControlExtensions 类

AddRadioButton 重载

Microsoft.Office.Tools.Excel 命名空间