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
Application-level projects
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 |
---|---|
Adds a Button control to the specified range. |
|
Adds a Button control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a Label control to the specified range. |
|
Adds a Label control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a LinkLabel control to the specified range. |
|
Adds a LinkLabel control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a TextBox control to the specified range. |
|
Adds a TextBox control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a CheckBox control to the specified range. |
|
Adds a CheckBox control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a RadioButton control to the specified range. |
|
Adds a RadioButton control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a PictureBox control to the specified range. |
|
Adds a PictureBox control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a CheckedListBox control to the specified range. |
|
Adds a CheckedListBox control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a ComboBox control to the specified range. |
|
Adds a ComboBox control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a ListView control to the specified range, setting the position and size of control. |
|
Adds a ListView control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a TreeView control to the specified range. |
|
Adds a TreeView control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a DateTimePicker control to the specified range. |
|
Adds a DateTimePicker control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a MonthCalendar control to the specified range. |
|
Adds a MonthCalendar control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a DomainUpDown control to the specified range. |
|
Adds a DomainUpDown control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a NumericUpDown control to the specified range. |
|
Adds a NumericUpDown control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a TrackBar control to the specified range. |
|
Adds a TrackBar control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a RichTextBox control to the specified range. |
|
Adds a RichTextBox control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a DataGridView control to the specified range. |
|
Adds a DataGridView control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a HScrollBar control to the specified range. |
|
Adds a HScrollBar control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a VScrollBar control to the specified range. |
|
Adds a VScrollBar control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a PropertyGrid control to the specified range. |
|
Adds a PropertyGrid control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a WebBrowser control to the specified range. |
|
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 |
---|---|
Adds a Button control at the start of the specified range. |
|
Adds a Button control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a Label control at the start of the specified range. |
|
Adds a Label control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a LinkLabel control at the start of the specified range. |
|
Adds a LinkLabel control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a TextBox control at the start of the specified range. |
|
Adds a TextBox control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a CheckBox control at the start of the specified range. |
|
Adds a CheckBox control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a RadioButton control at the start of the specified range. |
|
Adds a RadioButton control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a PictureBox control at the start of the specified range. |
|
Adds a PictureBox control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a CheckedListBox control at the start of the specified range. |
|
Adds a CheckedListBox control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a ComboBox control at the start of the specified range. |
|
Adds a ComboBox control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a ListView control to the specified range, setting the position and size of control. |
|
Adds a ListView control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a TreeView control at the start of the specified range. |
|
Adds a TreeView control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a DateTimePicker control at the start of the specified range. |
|
Adds a DateTimePicker control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a MonthCalendar control at the start of the specified range. |
|
Adds a MonthCalendar control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a DomainUpDown control at the start of the specified range. |
|
Adds a DomainUpDown control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a NumericUpDown control at the start of the specified range. |
|
Adds a NumericUpDown control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a TrackBar control at the start of the specified range. |
|
Adds a TrackBar control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a RichTextBox control at the start of the specified range. |
|
Adds a RichTextBox control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a DataGridView control at the start of the specified range. |
|
Adds a DataGridView control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a HScrollBar control at the start of the specified range. |
|
Adds a HScrollBar control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a VScrollBar control at the start of the specified range. |
|
Adds a VScrollBar control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a PropertyGrid control at the start of the specified range. |
|
Adds a PropertyGrid control at the specified position rather than in a range. The coordinates are represented in points. |
|
Adds a WebBrowser control at the start of the specified range. |
|
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