Partager via


ControlExtensions Class

Definition

Provides extension methods you can use to add Windows Forms controls to Excel worksheets that have been customized by using the Office development tools in Visual Studio.

public ref class ControlExtensions abstract sealed
[System.Diagnostics.DebuggerNonUserCode]
public static class ControlExtensions
[<System.Diagnostics.DebuggerNonUserCode>]
type ControlExtensions = class
Public Module ControlExtensions
Inheritance
ControlExtensions
Attributes

Examples

The following code example uses the AddButton method to add a Button control to cell A1, and then adds text to the button. To use this example, run it from the Sheet1 class in a document-level project.

private void ExcelRangeAddButton()
{

    Microsoft.Office.Tools.Excel.Controls.Button button1 =
        this.Controls.AddButton(this.Range["A1"], "button1");
    button1.Text = "OK";
}
Private Sub ExcelRangeAddButton()

    Dim Button1 As Microsoft.Office.Tools.Excel. _
      Controls.Button = Me.Controls.AddButton( _
      Me.Range("A1"), "Button1")
    Button1.Text = "OK"

End Sub

Remarks

The ControlExtensions methods are extension methods that are available on the ControlCollection object returned by the Microsoft.Office.Tools.Excel.Worksheet.Controls property (in an application-level project) or the Microsoft.Office.Tools.Excel.WorksheetBase.Controls property (in a document-level project) at run time. To add a specific control to a document, use the method that includes the name of the control in the method name. For example, to add a Button, use the AddButton method.

For more information about controls to a document, see Adding Controls to Office Documents at Run Time. For more information about extension methods, see Extension Methods and Extension Methods.

Note

In Excel add-in projects that target the .NET Framework 4, you must add a reference to the Microsoft.Office.Tools.Excel.v4.0.Utilities.dll assembly before you can access the ControlExtensions methods.

Methods

AddButton(ControlCollection, Double, Double, Double, Double, String)

Adds a new Button control to the worksheet in the specified size and location.

AddButton(ControlCollection, Range, String)

Adds a new Button control to the worksheet at the range specified.

AddCheckBox(ControlCollection, Double, Double, Double, Double, String)

Adds a new CheckBox control to the worksheet in the specified size and location.

AddCheckBox(ControlCollection, Range, String)

Adds a new CheckBox control to the worksheet at the range specified.

AddCheckedListBox(ControlCollection, Double, Double, Double, Double, String)

Adds a new CheckedListBox control to the worksheet in the specified size and location.

AddCheckedListBox(ControlCollection, Range, String)

Adds a new CheckedListBox control to the worksheet at the range specified.

AddComboBox(ControlCollection, Double, Double, Double, Double, String)

Adds a new ComboBox control to the worksheet in the specified size and location.

AddComboBox(ControlCollection, Range, String)

Adds a new ComboBox control to the worksheet at the range specified.

AddDataGridView(ControlCollection, Double, Double, Double, Double, String)

Adds a new DataGridView control to the worksheet in the specified size and location.

AddDataGridView(ControlCollection, Range, String)

Adds a new DataGridView control to the worksheet at the range specified.

AddDateTimePicker(ControlCollection, Double, Double, Double, Double, String)

Adds a new DateTimePicker control to the worksheet in the specified size and location.

AddDateTimePicker(ControlCollection, Range, String)

Adds a new DateTimePicker control to the worksheet at the range specified.

AddDomainUpDown(ControlCollection, Double, Double, Double, Double, String)

Adds a new DomainUpDown control to the worksheet in the specified size and location.

AddDomainUpDown(ControlCollection, Range, String)

Adds a new DomainUpDown control to the worksheet at the range specified.

AddHScrollBar(ControlCollection, Double, Double, Double, Double, String)

Adds a new HScrollBar control to the worksheet in the specified size and location.

AddHScrollBar(ControlCollection, Range, String)

Adds a new HScrollBar control to the worksheet at the range specified.

AddLabel(ControlCollection, Double, Double, Double, Double, String)

Adds a new Label control to the worksheet in the specified size and location.

AddLabel(ControlCollection, Range, String)

Adds a new Label control to the worksheet at the range specified.

AddLinkLabel(ControlCollection, Double, Double, Double, Double, String)

Adds a new LinkLabel control to the worksheet in the specified size and location.

AddLinkLabel(ControlCollection, Range, String)

Adds a new LinkLabel control to the worksheet at the range specified.

AddListBox(ControlCollection, Double, Double, Double, Double, String)

Adds a new ListBox control to the worksheet in the specified size and location.

AddListBox(ControlCollection, Range, String)

Adds a new ListBox control to the worksheet at the range specified.

AddListView(ControlCollection, Double, Double, Double, Double, String)

Adds a new ListView control to the worksheet in the specified size and location.

AddListView(ControlCollection, Range, String)

Adds a new ListView control to the worksheet at the range specified.

AddMaskedTextBox(ControlCollection, Double, Double, Double, Double, String)

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

AddMaskedTextBox(ControlCollection, Range, String)

Adds a new MaskedTextBox control to the worksheet at the range specified.

AddMonthCalendar(ControlCollection, Double, Double, Double, Double, String)

Adds a new MonthCalendar control to the worksheet in the specified size and location.

AddMonthCalendar(ControlCollection, Range, String)

Adds a new MonthCalendar control to the worksheet at the range specified.

AddNumericUpDown(ControlCollection, Double, Double, Double, Double, String)

Adds a new NumericUpDown control to the worksheet in the specified size and location.

AddNumericUpDown(ControlCollection, Range, String)

Adds a new NumericUpDown control to the worksheet at the range specified.

AddPictureBox(ControlCollection, Double, Double, Double, Double, String)

Adds a new PictureBox control to the worksheet in the specified size and location.

AddPictureBox(ControlCollection, Range, String)

Adds a new PictureBox control to the worksheet at the range specified.

AddProgressBar(ControlCollection, Double, Double, Double, Double, String)

Adds a new ProgressBar control to the worksheet in the specified size and location.

AddProgressBar(ControlCollection, Range, String)

Adds a new ProgressBar control to the worksheet at the range specified.

AddPropertyGrid(ControlCollection, Double, Double, Double, Double, String)

Adds a new PropertyGrid control to the worksheet in the specified size and location.

AddPropertyGrid(ControlCollection, Range, String)

Adds a new PropertyGrid 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.

AddRadioButton(ControlCollection, Range, String)

Adds a new RadioButton control to the worksheet at the range specified.

AddRichTextBox(ControlCollection, Double, Double, Double, Double, String)

Adds a new RichTextBox control to the worksheet in the specified size and location.

AddRichTextBox(ControlCollection, Range, String)

Adds a new RichTextBox control to the worksheet at the range specified.

AddTextBox(ControlCollection, Double, Double, Double, Double, String)

Adds a new TextBox control to the worksheet in the specified size and location.

AddTextBox(ControlCollection, Range, String)

Adds a new TextBox control to the worksheet at the range specified.

AddTrackBar(ControlCollection, Double, Double, Double, Double, String)

Adds a new TrackBar control to the worksheet in the specified size and location.

AddTrackBar(ControlCollection, Range, String)

Adds a new TrackBar control to the worksheet at the range specified.

AddTreeView(ControlCollection, Double, Double, Double, Double, String)

Adds a new TreeView control to the worksheet in the specified size and location.

AddTreeView(ControlCollection, Range, String)

Adds a new TreeView control to the worksheet at the range specified.

AddVScrollBar(ControlCollection, Double, Double, Double, Double, String)

Adds a new VScrollBar control to the worksheet in the specified size and location.

AddVScrollBar(ControlCollection, Range, String)

Adds a new VScrollBar control to the worksheet at the range specified.

AddWebBrowser(ControlCollection, Double, Double, Double, Double, String)

Adds a new WebBrowser control to the worksheet in the specified size and location.

AddWebBrowser(ControlCollection, Range, String)

Adds a new WebBrowser control to the worksheet at the range specified.

Applies to