共用方式為


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

將新的 RadioButton 控制項加入至指定之大小和位置的文件中。

命名空間:  Microsoft.Office.Tools.Word
組件:  Microsoft.Office.Tools.Word.v4.0.Utilities (在 Microsoft.Office.Tools.Word.v4.0.Utilities.dll 中)

語法

'宣告
<ExtensionAttribute> _
Public Shared Function AddRadioButton ( _
    controls As ControlCollection, _
    left As Single, _
    top As Single, _
    width As Single, _
    height As Single, _
    name As String _
) As RadioButton
public static RadioButton AddRadioButton(
    this ControlCollection controls,
    float left,
    float top,
    float width,
    float height,
    string name
)

參數

  • left
    型別:System.Single
    控制項左邊緣和文件左邊緣之間的距離 (以點為單位)。
  • top
    型別:System.Single
    控制項上邊緣和文件上邊緣之間的距離 (以點為單位)。
  • width
    型別:System.Single
    控制項的寬度 (以點為單位)。
  • height
    型別:System.Single
    控制項的高度 (以點為單位)。

傳回值

型別:Microsoft.Office.Tools.Word.Controls.RadioButton
已加入至文件的控制項。

使用注意事項

在 Visual Basic 和 C# 中,您可以在任何 ControlCollection 型別物件中呼叫這個方法以做為執行個體。使用執行個體方法語法呼叫這個方法時,請省略第一個參數。如需詳細資訊,請參閱擴充方法 (Visual Basic)擴充方法 (C# 程式設計手冊)

例外狀況

例外狀況 條件
ArgumentNullException

name 引數為 nullNull 參照 (即 Visual Basic 中的 Nothing),或長度為 0。

ControlNameAlreadyExistsException

具有相同名稱的控制項已經存在於 ControlCollection 執行個體中。

備註

這個方法可以讓您將 RadioButton 物件加入至 ControlCollection 的尾端。

若要移除以程式設計方式加入的 RadioButton,請使用 Remove 方法。

當您將多個選項按鈕直接加入文件中時,這些選項按鈕並不會互斥。 您可以撰寫程式碼讓選項按鈕互斥,但最好是能先將選項按鈕加入至使用者控制項,然後再將該使用者控制項加入至文件中。

範例

下列程式碼範例加入兩個 RadioButton 控制項至文件,然後指派文字給每個控制項。 若要使用這個範例,請在文件層級專案中的 ThisDocument 類別執行。

Private Sub WordAddRadioButton()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Dim RadioButton1 As Microsoft.Office.Tools.Word.Controls. _
        RadioButton = Me.Controls.AddRadioButton(0, 0, 78, 18, _
        "RadioButton1")
    Dim RadioButton2 As Microsoft.Office.Tools.Word.Controls. _
        RadioButton = Me.Controls.AddRadioButton(0, 18, 78, 18, _
        "RadioButton2")
    RadioButton1.Text = "Bold"
    RadioButton2.Text = "Italic"
End Sub 
private void WordAddRadioButton()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    Microsoft.Office.Tools.Word.Controls.RadioButton
         radioButton1 = this.Controls.AddRadioButton(
         0, 0, 78, 18, "radioButton1");
    Microsoft.Office.Tools.Word.Controls.RadioButton
         radioButton2 = this.Controls.AddRadioButton(
         0, 18, 78, 18, "radioButton2");
    radioButton1.Text = "Bold";
    radioButton2.Text = "Italic";
}

.NET Framework 安全性

請參閱

參考

ControlExtensions 類別

AddRadioButton 多載

Microsoft.Office.Tools.Word 命名空間