Helper Methods for Windows Forms Controls

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Document-level projects

  • Excel 2003

  • Excel 2007

  • Word 2003

  • Word 2007

Application-level projects

  • Excel 2007

  • Word 2007

For more information, see Features Available by Application and Project Type.

You can programmatically add Windows Forms controls to a Microsoft Office Word document and Microsoft Office Excel workbook at run time. Use the helper methods that are in the Microsoft.Office.Tools.Excel.ControlCollection and Microsoft.Office.Tools.Word.ControlCollection classes. For more information, see Adding Controls to Office Documents at Run Time.

Helper Methods for Excel

The Microsoft.Office.Tools.Excel.ControlCollection class provides a number of helper methods that can be used to programmatically add Windows Forms controls to Excel documents. 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 automatically resizes when cells within the range are resized.

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

Helper method

Description

AddButton(Range, String)

Adds a Button control to the specified range.

AddButton(Range, Single, Single, String)

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

AddLabel(Range, String)

Adds a Label control to the specified range.

AddLabel(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(Range, String)

Adds a LinkLabel control to the specified range.

AddLinkLabel(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(Range, String)

Adds a TextBox control to the specified range.

AddTextBox(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(Range, String)

Adds a CheckBox control to the specified range.

AddCheckBox(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(Range, String)

Adds a RadioButton control to the specified range.

AddRadioButton(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(Range, String)

Adds a PictureBox control to the specified range.

AddPictureBox(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(Range, String)

Adds a CheckedListBox control to the specified range.

AddCheckedListBox(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(Range, String)

Adds a ComboBox control to the specified range.

AddComboBox(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(Range, String)

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

AddListView(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(Range, String)

Adds a TreeView control to the specified range.

AddTreeView(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(Range, String)

Adds a DateTimePicker control to the specified range.

AddDateTimePicker(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(Range, String)

Adds a MonthCalendar control to the specified range.

AddMonthCalendar(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(Range, String)

Adds a DomainUpDown control to the specified range.

AddDomainUpDown(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(Range, String)

Adds a NumericUpDown control to the specified range.

AddNumericUpDown(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(Range, String)

Adds a TrackBar control to the specified range.

AddTrackBar(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(Range, String)

Adds a RichTextBox control to the specified range.

AddRichTextBox(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(Range, String)

Adds a DataGridView control to the specified range.

AddDataGridView(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(Range, String)

Adds a HScrollBar control to the specified range.

AddHScrollBar(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(Range, String)

Adds a VScrollBar control to the specified range.

AddVScrollBar(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(Range, String)

Adds a PropertyGrid control to the specified range.

AddPropertyGrid(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(Range, String)

Adds a WebBrowser control to the specified range.

AddWebBrowser(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

The Microsoft.Office.Tools.Word.ControlCollection class provides a number of helper methods that can be used to programmatically add Windows Forms controls to Word documents. 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.

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

Helper method

Description

AddButton(Range, Single, Single, String)

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

AddButton(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(Range, Single, Single, String)

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

AddLabel(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(Range, Single, Single, String)

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

AddLinkLabel(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(Range, Single, Single, String)

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

AddTextBox(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(Range, Single, Single, String)

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

AddCheckBox(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(Range, Single, Single, String)

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

AddRadioButton(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(Range, Single, Single, String)

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

AddPictureBox(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(Range, Single, Single, String)

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

AddCheckedListBox(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(Range, Single, Single, String)

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

AddComboBox(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(Range, Single, Single, String)

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

AddListView(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(Range, Single, Single, String)

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

AddTreeView(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(Range, Single, Single, String)

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

AddDateTimePicker(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(Range, Single, Single, String)

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

AddMonthCalendar(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(Range, Single, Single, String)

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

AddDomainUpDown(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(Range, Single, Single, String)

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

AddNumericUpDown(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(Range, Single, Single, String)

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

AddTrackBar(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(Range, Single, Single, String)

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

AddRichTextBox(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(Range, Single, Single, String)

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

AddDataGridView(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(Range, Single, Single, String)

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

AddHScrollBar(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(Range, Single, Single, String)

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

AddVScrollBar(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(Range, Single, Single, String)

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

AddPropertyGrid(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(Range, Single, Single, String)

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

AddWebBrowser(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