ControlExtensions.AddRadioButton Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
AddRadioButton(ControlCollection, Double, Double, Double, Double, String) |
Adds a new RadioButton control to the worksheet in the specified size and location. |
AddRadioButton(ControlCollection, Range, String) |
Adds a new RadioButton control to the worksheet at the range specified. |
AddRadioButton(ControlCollection, Double, Double, Double, Double, String)
Adds a new RadioButton control to the worksheet in the specified size and location.
public:
[System::Runtime::CompilerServices::Extension]
static Microsoft::Office::Tools::Excel::Controls::RadioButton ^ AddRadioButton(Microsoft::Office::Tools::Excel::ControlCollection ^ controls, double left, double top, double width, double height, System::String ^ name);
public static Microsoft.Office.Tools.Excel.Controls.RadioButton AddRadioButton (this Microsoft.Office.Tools.Excel.ControlCollection controls, double left, double top, double width, double height, string name);
static member AddRadioButton : Microsoft.Office.Tools.Excel.ControlCollection * double * double * double * double * string -> Microsoft.Office.Tools.Excel.Controls.RadioButton
<Extension()>
Public Function AddRadioButton (controls As ControlCollection, left As Double, top As Double, width As Double, height As Double, 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
- Double
The distance in points between the left edge of the control and the left edge of the worksheet.
- top
- Double
The distance in points between the top edge of the control and the top edge of the worksheet.
- width
- Double
The width of the control in points.
- height
- Double
The height of the control in points.
- name
- String
The name of the control.
Returns
The RadioButton control that was added to the ControlCollection instance.
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 top of the worksheet, and then assigns text to each control. To use this example, run it from the Sheet1
class in a document-level project.
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;
}
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
Remarks
The AddRadioButton method enables you to add RadioButton objects to the end of the ControlCollection. To remove a RadioButton control that was previously 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, String)
Adds a new RadioButton control to the worksheet at the range specified.
public:
[System::Runtime::CompilerServices::Extension]
static Microsoft::Office::Tools::Excel::Controls::RadioButton ^ AddRadioButton(Microsoft::Office::Tools::Excel::ControlCollection ^ controls, Microsoft::Office::Interop::Excel::Range ^ range, System::String ^ name);
public static Microsoft.Office.Tools.Excel.Controls.RadioButton AddRadioButton (this Microsoft.Office.Tools.Excel.ControlCollection controls, Microsoft.Office.Interop.Excel.Range range, string name);
static member AddRadioButton : Microsoft.Office.Tools.Excel.ControlCollection * Microsoft.Office.Interop.Excel.Range * string -> Microsoft.Office.Tools.Excel.Controls.RadioButton
<Extension()>
Public Function AddRadioButton (controls As ControlCollection, range As Range, 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.
- name
- String
The name of the control that can be used to index the control in the ControlCollection instance.
Returns
The RadioButton control that was added to the ControlCollection instance.
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. Multi-area ranges cannot be used. The range should be on the same worksheet as the ControlCollection instance.
Examples
The following code example adds two RadioButton controls to the worksheet in cells A1 and A2, and then assigns text to each control. To use this example, run it from the Sheet1
class in a document-level project.
private void ExcelRangeAddRadioButton()
{
Microsoft.Office.Tools.Excel.Controls.RadioButton
radioButton1 = this.Controls.AddRadioButton(
this.Range["A1"], "radioButton1");
Microsoft.Office.Tools.Excel.Controls.RadioButton
radioButton2 = this.Controls.AddRadioButton(
this.Range["A2"], "radioButton2");
radioButton1.Text = "Bold";
radioButton2.Text = "Italic";
radioButton2.Checked = false;
}
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
Remarks
The AddRadioButton method enables you to add RadioButton objects to the end of the ControlCollection. To remove a RadioButton that was previously added programmatically, use the Remove method.
The control automatically resizes when the range is resized.
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.