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

更新:2007 年 11 月

按照指定的大小和位置向文档中添加一个新的 RadioButton 控件。

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

语法

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

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

参数

  • width
    类型:System.Single

    控件的宽度(以磅为单位)。

  • height
    类型:System.Single

    控件的高度(以磅为单位)。

返回值

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

添加到 ControlCollection 实例的 RadioButton 控件。

异常

异常 条件
ArgumentNullException

name 或 range 参数为 nullnull 引用(在 Visual Basic 中为 Nothing),或者 name 参数长度为零。

ControlNameAlreadyExistsException

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

InvalidRangeException

指定的范围无效。

备注

此方法使您能够将 RadioButton 对象添加到 ControlCollection 的末尾。

若要移除通过编程方式添加的 RadioButton,请使用 Remove 方法。

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

示例

下面的代码示例向文档的第一和第二个段落添加两个 RadioButton 控件,然后向每个控件分配文本。

Private Sub WordRangeAddRadioButton()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Dim RadioButton1 As Microsoft.Office.Tools.Word.Controls. _
        RadioButton = Me.Controls.AddRadioButton( _
        Me.Paragraphs(1).Range, 78, 18, "RadioButton1")
    Dim RadioButton2 As Microsoft.Office.Tools.Word.Controls. _
        RadioButton = Me.Controls.AddRadioButton( _
        Me.Paragraphs(2).Range, 78, 18, "RadioButton2")
    RadioButton1.Text = "Bold"
    RadioButton2.Text = "Italic"

End Sub 

private void WordRangeAddRadioButton()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    this.Paragraphs[1].Range.InsertParagraphBefore();
    Microsoft.Office.Tools.Word.Controls.RadioButton
         radioButton1 = this.Controls.AddRadioButton(
         this.Paragraphs[1].Range, 78, 18, "radioButton1");
    Microsoft.Office.Tools.Word.Controls.RadioButton
         radioButton2 = this.Controls.AddRadioButton(
         this.Paragraphs[2].Range, 78, 18, "radioButton2");
    radioButton1.Text = "Bold";
    radioButton2.Text = "Italic";

}

权限

另请参见

参考

ControlCollection 类

ControlCollection 成员

AddRadioButton 重载

Microsoft.Office.Tools.Word 命名空间