共用方式為


ControlExtensions.AddRadioButton Method

Definition

Overloads

AddRadioButton(ControlCollection, Single, Single, Single, Single, String)

Adds a new RadioButton control to the document in the specified size and location.

AddRadioButton(ControlCollection, Range, Single, Single, String)

Adds a new RadioButton control to the document in the specified size and location.

AddRadioButton(ControlCollection, Single, Single, Single, Single, String)

Adds a new RadioButton control to the document in the specified size and location.

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Office::Tools::Word::Controls::RadioButton ^ AddRadioButton(Microsoft::Office::Tools::Word::ControlCollection ^ controls, float left, float top, float width, float height, System::String ^ name);
public static Microsoft.Office.Tools.Word.Controls.RadioButton AddRadioButton (this Microsoft.Office.Tools.Word.ControlCollection controls, float left, float top, float width, float height, string name);
static member AddRadioButton : Microsoft.Office.Tools.Word.ControlCollection * single * single * single * single * string -> Microsoft.Office.Tools.Word.Controls.RadioButton
<Extension()>
Public Function AddRadioButton (controls As ControlCollection, left As Single, top As Single, width As Single, height As Single, name As String) As RadioButton

Parameters

controls
ControlCollection

The collection to add the control to. Do not supply this parameter yourself. When you call this method on the collection returned by the Controls property (in an application-level project) or the Controls property (in a document-level project), this parameter is supplied automatically.

left
Single

The distance in points between the left edge of the control and the left edge of the document.

top
Single

The distance in points between the top edge of the control and the top edge of the document.

width
Single

The width of the control in points.

height
Single

The height of the control in points.

name
String

The name that can be used to index the control in the ControlCollection instance.

Returns

The control that was added to the document.

Exceptions

The name argument is null or has zero length.

A control with the same name is already in the ControlCollection instance.

Examples

The following code example adds two RadioButton controls to the document, and then assigns text to each control. To use this example, run it from the ThisDocument class in a document-level project.

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";
}
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 

Remarks

This method enables you to add RadioButton objects to the end of the ControlCollection.

To remove a RadioButton that was added programmatically, use the Remove method.

When you add multiple radio buttons directly to the document, the radio buttons are not mutually exclusive. You can write code to make the radio buttons mutually exclusive; however, the preferred approach is to add the radio buttons to a user control and then add the user control to the document.

Applies to

AddRadioButton(ControlCollection, Range, Single, Single, String)

Adds a new RadioButton control to the document in the specified size and location.

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Office::Tools::Word::Controls::RadioButton ^ AddRadioButton(Microsoft::Office::Tools::Word::ControlCollection ^ controls, Microsoft::Office::Interop::Word::Range ^ range, float width, float height, System::String ^ name);
public static Microsoft.Office.Tools.Word.Controls.RadioButton AddRadioButton (this Microsoft.Office.Tools.Word.ControlCollection controls, Microsoft.Office.Interop.Word.Range range, float width, float height, string name);
static member AddRadioButton : Microsoft.Office.Tools.Word.ControlCollection * Microsoft.Office.Interop.Word.Range * single * single * string -> Microsoft.Office.Tools.Word.Controls.RadioButton
<Extension()>
Public Function AddRadioButton (controls As ControlCollection, range As Range, width As Single, height As Single, name As String) As RadioButton

Parameters

controls
ControlCollection

The collection to add the control to. Do not supply this parameter yourself. When you call this method on the collection returned by the Controls property (in an application-level project) or the Controls property (in a document-level project), this parameter is supplied automatically.

range
Range

The location of the control.

width
Single

The width of the control in points.

height
Single

The height of the control in points.

name
String

The name that can be used to index the control in the ControlCollection instance.

Returns

The control that was added to the document.

Exceptions

The name or range argument is null, or the name argument has zero length.

A control with the same name is already in the ControlCollection instance.

The range that was specified is not valid.

Examples

The following code example adds two RadioButton controls to the document in the first and second paragraphs, and then assigns text to each control. To use this example, run it from the ThisDocument class in a document-level project.

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";

}
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 

Remarks

This method enables you to add RadioButton objects to the end of the ControlCollection.

To remove a RadioButton that was added programmatically, use the Remove method.

When you add multiple radio buttons directly to the document, the radio buttons are not mutually exclusive. You can write code to make the radio buttons mutually exclusive; however, the preferred approach is to add the radio buttons to a user control and then add the user control to the document.

Applies to