Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ControlExtensions Class
Collapse the table of content
Expand the table of content

ControlExtensions Class

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.

System.Object
  Microsoft.Office.Tools.Excel.ControlExtensions

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

public static class ControlExtensions

  NameDescription
Public methodStatic memberAddButton(ControlCollection, Range, String)Adds a new Button control to the worksheet at the range specified.
Public methodStatic memberAddButton(ControlCollection, Double, Double, Double, Double, String)Adds a new Button control to the worksheet in the specified size and location.
Public methodStatic memberAddCheckBox(ControlCollection, Range, String)Adds a new CheckBox control to the worksheet at the range specified.
Public methodStatic memberAddCheckBox(ControlCollection, Double, Double, Double, Double, String)Adds a new CheckBox control to the worksheet in the specified size and location.
Public methodStatic memberAddCheckedListBox(ControlCollection, Range, String)Adds a new CheckedListBox control to the worksheet at the range specified.
Public methodStatic memberAddCheckedListBox(ControlCollection, Double, Double, Double, Double, String)Adds a new CheckedListBox control to the worksheet in the specified size and location.
Public methodStatic memberAddComboBox(ControlCollection, Range, String)Adds a new ComboBox control to the worksheet at the range specified.
Public methodStatic memberAddComboBox(ControlCollection, Double, Double, Double, Double, String)Adds a new ComboBox control to the worksheet in the specified size and location.
Public methodStatic memberAddDataGridView(ControlCollection, Range, String)Adds a new DataGridView control to the worksheet at the range specified.
Public methodStatic memberAddDataGridView(ControlCollection, Double, Double, Double, Double, String)Adds a new DataGridView control to the worksheet in the specified size and location.
Public methodStatic memberAddDateTimePicker(ControlCollection, Range, String)Adds a new DateTimePicker control to the worksheet at the range specified.
Public methodStatic memberAddDateTimePicker(ControlCollection, Double, Double, Double, Double, String)Adds a new DateTimePicker control to the worksheet in the specified size and location.
Public methodStatic memberAddDomainUpDown(ControlCollection, Range, String)Adds a new DomainUpDown control to the worksheet at the range specified.
Public methodStatic memberAddDomainUpDown(ControlCollection, Double, Double, Double, Double, String)Adds a new DomainUpDown control to the worksheet in the specified size and location.
Public methodStatic memberAddHScrollBar(ControlCollection, Range, String)Adds a new HScrollBar control to the worksheet at the range specified.
Public methodStatic memberAddHScrollBar(ControlCollection, Double, Double, Double, Double, String)Adds a new HScrollBar control to the worksheet in the specified size and location.
Public methodStatic memberAddLabel(ControlCollection, Range, String)Adds a new Label control to the worksheet at the range specified.
Public methodStatic memberAddLabel(ControlCollection, Double, Double, Double, Double, String)Adds a new Label control to the worksheet in the specified size and location.
Public methodStatic memberAddLinkLabel(ControlCollection, Range, String)Adds a new LinkLabel control to the worksheet at the range specified.
Public methodStatic memberAddLinkLabel(ControlCollection, Double, Double, Double, Double, String)Adds a new LinkLabel control to the worksheet in the specified size and location.
Public methodStatic memberAddListBox(ControlCollection, Range, String)Adds a new ListBox control to the worksheet at the range specified.
Public methodStatic memberAddListBox(ControlCollection, Double, Double, Double, Double, String)Adds a new ListBox control to the worksheet in the specified size and location.
Public methodStatic memberAddListView(ControlCollection, Range, String)Adds a new ListView control to the worksheet at the range specified.
Public methodStatic memberAddListView(ControlCollection, Double, Double, Double, Double, String)Adds a new ListView control to the worksheet in the specified size and location.
Public methodStatic memberAddMaskedTextBox(ControlCollection, Range, String)Adds a new MaskedTextBox control to the worksheet at the range specified.
Public methodStatic memberAddMaskedTextBox(ControlCollection, Double, Double, Double, Double, String)Adds a new MaskedTextBox control to the document in the specified size and location.
Public methodStatic memberAddMonthCalendar(ControlCollection, Range, String)Adds a new MonthCalendar control to the worksheet at the range specified.
Public methodStatic memberAddMonthCalendar(ControlCollection, Double, Double, Double, Double, String)Adds a new MonthCalendar control to the worksheet in the specified size and location.
Public methodStatic memberAddNumericUpDown(ControlCollection, Range, String)Adds a new NumericUpDown control to the worksheet at the range specified.
Public methodStatic memberAddNumericUpDown(ControlCollection, Double, Double, Double, Double, String)Adds a new NumericUpDown control to the worksheet in the specified size and location.
Public methodStatic memberAddPictureBox(ControlCollection, Range, String)Adds a new PictureBox control to the worksheet at the range specified.
Public methodStatic memberAddPictureBox(ControlCollection, Double, Double, Double, Double, String)Adds a new PictureBox control to the worksheet in the specified size and location.
Public methodStatic memberAddProgressBar(ControlCollection, Range, String)Adds a new ProgressBar control to the worksheet at the range specified.
Public methodStatic memberAddProgressBar(ControlCollection, Double, Double, Double, Double, String)Adds a new ProgressBar control to the worksheet in the specified size and location.
Public methodStatic memberAddPropertyGrid(ControlCollection, Range, String)Adds a new PropertyGrid control to the worksheet at the range specified.
Public methodStatic memberAddPropertyGrid(ControlCollection, Double, Double, Double, Double, String)Adds a new PropertyGrid control to the worksheet in the specified size and location.
Public methodStatic memberAddRadioButton(ControlCollection, Range, String)Adds a new RadioButton control to the worksheet at the range specified.
Public methodStatic memberAddRadioButton(ControlCollection, Double, Double, Double, Double, String)Adds a new RadioButton control to the worksheet in the specified size and location.
Public methodStatic memberAddRichTextBox(ControlCollection, Range, String)Adds a new RichTextBox control to the worksheet at the range specified.
Public methodStatic memberAddRichTextBox(ControlCollection, Double, Double, Double, Double, String)Adds a new RichTextBox control to the worksheet in the specified size and location.
Public methodStatic memberAddTextBox(ControlCollection, Range, String)Adds a new TextBox control to the worksheet at the range specified.
Public methodStatic memberAddTextBox(ControlCollection, Double, Double, Double, Double, String)Adds a new TextBox control to the worksheet in the specified size and location.
Public methodStatic memberAddTrackBar(ControlCollection, Range, String)Adds a new TrackBar control to the worksheet at the range specified.
Public methodStatic memberAddTrackBar(ControlCollection, Double, Double, Double, Double, String)Adds a new TrackBar control to the worksheet in the specified size and location.
Public methodStatic memberAddTreeView(ControlCollection, Range, String)Adds a new TreeView control to the worksheet at the range specified.
Public methodStatic memberAddTreeView(ControlCollection, Double, Double, Double, Double, String)Adds a new TreeView control to the worksheet in the specified size and location.
Public methodStatic memberAddVScrollBar(ControlCollection, Range, String)Adds a new VScrollBar control to the worksheet at the range specified.
Public methodStatic memberAddVScrollBar(ControlCollection, Double, Double, Double, Double, String)Adds a new VScrollBar control to the worksheet in the specified size and location.
Public methodStatic memberAddWebBrowser(ControlCollection, Range, String)Adds a new WebBrowser control to the worksheet at the range specified.
Public methodStatic memberAddWebBrowser(ControlCollection, Double, Double, Double, Double, String)Adds a new WebBrowser control to the worksheet in the specified size and location.
Top

The ControlExtensions methods are extension methods that are available on the ControlCollection object returned by the Worksheet.Controls property (in an application-level project) or the 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 (C# Programming Guide) and Extension Methods (Visual Basic).

NoteNote

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.

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2015 Microsoft