Share via


Helper Methods for Windows Forms Controls

You can programmatically add Windows Forms controls to a Microsoft Office Word document and Microsoft Office Excel workbook at run time by using helper methods that are available in your project. For more information, see Adding Controls to Office Documents at Run Time.

Applies to: The information in this topic applies to document-level projects and application-level projects for the following applications: Excel 2007 and Excel 2010; Word 2007 and Word 2010. For more information, see Features Available by Office Application and Project Type.

Helper Methods for Excel

To add Windows Forms controls to a worksheet at run time, use helper 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). Each helper method is overloaded so that you can pass in a Range or the coordinates of a specific location. When you create a control by passing in a Range, the control automatically resizes when cells within the range are resized.

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 helper methods.

The following table lists the helper methods that you can use to programmatically add Windows Forms controls to Excel workbooks.

Helper method

Description

AddButton(ControlCollection, Range, String)

Adds a Button control to the specified range.

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

Adds a Button control at the specified position rather than in a range. The coordinates are represented in points.

AddLabel(ControlCollection, Range, String)

Adds a Label control to the specified range.

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

Adds a Label control at the specified position rather than in a range. The coordinates are represented in points.

AddLinkLabel(ControlCollection, Range, String)

Adds a LinkLabel control to the specified range.

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

Adds a LinkLabel control at the specified position rather than in a range. The coordinates are represented in points.

AddTextBox(ControlCollection, Range, String)

Adds a TextBox control to the specified range.

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

Adds a TextBox control at the specified position rather than in a range. The coordinates are represented in points.

AddCheckBox(ControlCollection, Range, String)

Adds a CheckBox control to the specified range.

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

Adds a CheckBox control at the specified position rather than in a range. The coordinates are represented in points.

AddRadioButton(ControlCollection, Range, String)

Adds a RadioButton control to the specified range.

AddRadioButton(ControlCollection, Double, Double, Double, Double, String)

Adds a RadioButton control at the specified position rather than in a range. The coordinates are represented in points.

AddPictureBox(ControlCollection, Range, String)

Adds a PictureBox control to the specified range.

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

Adds a PictureBox control at the specified position rather than in a range. The coordinates are represented in points.

AddCheckedListBox(ControlCollection, Range, String)

Adds a CheckedListBox control to the specified range.

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

Adds a CheckedListBox control at the specified position rather than in a range. The coordinates are represented in points.

AddComboBox(ControlCollection, Range, String)

Adds a ComboBox control to the specified range.

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

Adds a ComboBox control at the specified position rather than in a range. The coordinates are represented in points.

AddListView(ControlCollection, Range, String)

Adds a ListView control to the specified range, setting the position and size of control.

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

Adds a ListView control at the specified position rather than in a range. The coordinates are represented in points.

AddTreeView(ControlCollection, Range, String)

Adds a TreeView control to the specified range.

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

Adds a TreeView control at the specified position rather than in a range. The coordinates are represented in points.

AddDateTimePicker(ControlCollection, Range, String)

Adds a DateTimePicker control to the specified range.

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

Adds a DateTimePicker control at the specified position rather than in a range. The coordinates are represented in points.

AddMonthCalendar(ControlCollection, Range, String)

Adds a MonthCalendar control to the specified range.

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

Adds a MonthCalendar control at the specified position rather than in a range. The coordinates are represented in points.

AddDomainUpDown(ControlCollection, Range, String)

Adds a DomainUpDown control to the specified range.

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

Adds a DomainUpDown control at the specified position rather than in a range. The coordinates are represented in points.

AddNumericUpDown(ControlCollection, Range, String)

Adds a NumericUpDown control to the specified range.

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

Adds a NumericUpDown control at the specified position rather than in a range. The coordinates are represented in points.

AddTrackBar(ControlCollection, Range, String)

Adds a TrackBar control to the specified range.

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

Adds a TrackBar control at the specified position rather than in a range. The coordinates are represented in points.

AddRichTextBox(ControlCollection, Range, String)

Adds a RichTextBox control to the specified range.

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

Adds a RichTextBox control at the specified position rather than in a range. The coordinates are represented in points.

AddDataGridView(ControlCollection, Range, String)

Adds a DataGridView control to the specified range.

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

Adds a DataGridView control at the specified position rather than in a range. The coordinates are represented in points.

AddHScrollBar(ControlCollection, Range, String)

Adds a HScrollBar control to the specified range.

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

Adds a HScrollBar control at the specified position rather than in a range. The coordinates are represented in points.

AddVScrollBar(ControlCollection, Range, String)

Adds a VScrollBar control to the specified range.

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

Adds a VScrollBar control at the specified position rather than in a range. The coordinates are represented in points.

AddPropertyGrid(ControlCollection, Range, String)

Adds a PropertyGrid control to the specified range.

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

Adds a PropertyGrid control at the specified position rather than in a range. The coordinates are represented in points.

AddWebBrowser(ControlCollection, Range, String)

Adds a WebBrowser control to the specified range.

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

Adds a WebBrowser control at the specified position rather than in a range. The coordinates are represented in points.

Helper Methods for Word

To add Windows Forms controls to a document at run time, use helper methods that are available on the ControlCollection object returned by the Document.Controls property (in an application-level project) or the DocumentBase.Controls property (in a document-level project). Each method is overloaded so that you can pass in a Range or the coordinates of a specific location. When you create a control by passing in a Range, the control is added as an InlineShape at the start of the range. You cannot change the Top and Left properties of controls that are added in line with text. When you create a control by passing in coordinates, the control is added as a floating Shape at the specified location.

Note

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

The following table lists the helper methods that you can use to programmatically add Windows Forms controls to Word documents.

Helper method

Description

AddButton(ControlCollection, Range, Single, Single, String)

Adds a Button control at the start of the specified range.

AddButton(ControlCollection, Single, Single, Single, Single, String)

Adds a Button control at the specified position rather than in a range. The coordinates are represented in points.

AddLabel(ControlCollection, Range, Single, Single, String)

Adds a Label control at the start of the specified range.

AddLabel(ControlCollection, Single, Single, Single, Single, String)

Adds a Label control at the specified position rather than in a range. The coordinates are represented in points.

AddLinkLabel(ControlCollection, Range, Single, Single, String)

Adds a LinkLabel control at the start of the specified range.

AddLinkLabel(ControlCollection, Single, Single, Single, Single, String)

Adds a LinkLabel control at the specified position rather than in a range. The coordinates are represented in points.

AddTextBox(ControlCollection, Range, Single, Single, String)

Adds a TextBox control at the start of the specified range.

AddTextBox(ControlCollection, Single, Single, Single, Single, String)

Adds a TextBox control at the specified position rather than in a range. The coordinates are represented in points.

AddCheckBox(ControlCollection, Range, Single, Single, String)

Adds a CheckBox control at the start of the specified range.

AddCheckBox(ControlCollection, Single, Single, Single, Single, String)

Adds a CheckBox control at the specified position rather than in a range. The coordinates are represented in points.

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

Adds a RadioButton control at the start of the specified range.

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

Adds a RadioButton control at the specified position rather than in a range. The coordinates are represented in points.

AddPictureBox(ControlCollection, Range, Single, Single, String)

Adds a PictureBox control at the start of the specified range.

AddPictureBox(ControlCollection, Single, Single, Single, Single, String)

Adds a PictureBox control at the specified position rather than in a range. The coordinates are represented in points.

AddCheckedListBox(ControlCollection, Range, Single, Single, String)

Adds a CheckedListBox control at the start of the specified range.

AddCheckedListBox(ControlCollection, Single, Single, Single, Single, String)

Adds a CheckedListBox control at the specified position rather than in a range. The coordinates are represented in points.

AddComboBox(ControlCollection, Range, Single, Single, String)

Adds a ComboBox control at the start of the specified range.

AddComboBox(ControlCollection, Single, Single, Single, Single, String)

Adds a ComboBox control at the specified position rather than in a range. The coordinates are represented in points.

AddListView(ControlCollection, Range, Single, Single, String)

Adds a ListView control to the specified range, setting the position and size of control.

AddListView(ControlCollection, Single, Single, Single, Single, String)

Adds a ListView control at the specified position rather than in a range. The coordinates are represented in points.

AddTreeView(ControlCollection, Range, Single, Single, String)

Adds a TreeView control at the start of the specified range.

AddTreeView(ControlCollection, Single, Single, Single, Single, String)

Adds a TreeView control at the specified position rather than in a range. The coordinates are represented in points.

AddDateTimePicker(ControlCollection, Range, Single, Single, String)

Adds a DateTimePicker control at the start of the specified range.

AddDateTimePicker(ControlCollection, Single, Single, Single, Single, String)

Adds a DateTimePicker control at the specified position rather than in a range. The coordinates are represented in points.

AddMonthCalendar(ControlCollection, Range, Single, Single, String)

Adds a MonthCalendar control at the start of the specified range.

AddMonthCalendar(ControlCollection, Single, Single, Single, Single, String)

Adds a MonthCalendar control at the specified position rather than in a range. The coordinates are represented in points.

AddDomainUpDown(ControlCollection, Range, Single, Single, String)

Adds a DomainUpDown control at the start of the specified range.

AddDomainUpDown(ControlCollection, Single, Single, Single, Single, String)

Adds a DomainUpDown control at the specified position rather than in a range. The coordinates are represented in points.

AddNumericUpDown(ControlCollection, Range, Single, Single, String)

Adds a NumericUpDown control at the start of the specified range.

AddNumericUpDown(ControlCollection, Single, Single, Single, Single, String)

Adds a NumericUpDown control at the specified position rather than in a range. The coordinates are represented in points.

AddTrackBar(ControlCollection, Range, Single, Single, String)

Adds a TrackBar control at the start of the specified range.

AddTrackBar(ControlCollection, Single, Single, Single, Single, String)

Adds a TrackBar control at the specified position rather than in a range. The coordinates are represented in points.

AddRichTextBox(ControlCollection, Range, Single, Single, String)

Adds a RichTextBox control at the start of the specified range.

AddRichTextBox(ControlCollection, Single, Single, Single, Single, String)

Adds a RichTextBox control at the specified position rather than in a range. The coordinates are represented in points.

AddDataGridView(ControlCollection, Range, Single, Single, String)

Adds a DataGridView control at the start of the specified range.

AddDataGridView(ControlCollection, Single, Single, Single, Single, String)

Adds a DataGridView control at the specified position rather than in a range. The coordinates are represented in points.

AddHScrollBar(ControlCollection, Range, Single, Single, String)

Adds a HScrollBar control at the start of the specified range.

AddHScrollBar(ControlCollection, Single, Single, Single, Single, String)

Adds a HScrollBar control at the specified position rather than in a range. The coordinates are represented in points.

AddVScrollBar(ControlCollection, Range, Single, Single, String)

Adds a VScrollBar control at the start of the specified range.

AddVScrollBar(ControlCollection, Single, Single, Single, Single, String)

Adds a VScrollBar control at the specified position rather than in a range. The coordinates are represented in points.

AddPropertyGrid(ControlCollection, Range, Single, Single, String)

Adds a PropertyGrid control at the start of the specified range.

AddPropertyGrid(ControlCollection, Single, Single, Single, Single, String)

Adds a PropertyGrid control at the specified position rather than in a range. The coordinates are represented in points.

AddWebBrowser(ControlCollection, Range, Single, Single, String)

Adds a WebBrowser control at the start of the specified range.

AddWebBrowser(ControlCollection, Single, Single, Single, Single, String)

Adds a WebBrowser control at the specified position rather than in a range. The coordinates are represented in points.

See Also

Concepts

Adding Controls to Office Documents at Run Time

Windows Forms Controls on Office Documents Overview

Limitations of Windows Forms Controls on Office Documents

Other Resources

Controls on Office Documents