A control is a component on the document used to display information or accept user input. You can add Windows Forms controls to Microsoft Office Excel 2003 and Microsoft Office Word 2003 documents at design time or at run time. For example, you can add a ComboBox control to your worksheet so that users can select from a list of options. You can also add host controls, such as Bookmark controls and NamedRange controls, to Office documents. For more information, see Word Host Controls and Excel Host Controls.
Note |
|---|
| The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings. |
Adding Controls at Design Time
To drag a Windows Forms control to the document
-
Create or open an Excel Workbook project or Word Document project in Visual Studio so that the document is visible in the designer. For information on creating projects, see How to: Create Visual Studio Tools for Office Projects.
-
In the Common Controls tab of the Toolbox, click the control you want to add, and drag it to the document.
Note |
|---|
| When you select a control in Excel, you will see =EMBED("WinForms.Control.Host","") in the Formula Bar. This text is necessary and should not be deleted. |
To draw a Windows Forms control on the document
-
Create or open an Excel Workbook project or Word Document project in Visual Studio so that the document is visible in the designer. For information on creating projects, see How to: Create Visual Studio Tools for Office Projects.
-
In the Common Controls tab of the Toolbox, click the control you want to add.
-
On the document, click where you want the upper-left corner of the control to be located, and drag to where you want the lower-right corner of the control to be located.
The control is added to the document with the specified location and size.
Note |
|---|
| When you select a control in Excel, you will see =EMBED("WinForms.Control.Host","") in the Formula Bar. This text is necessary and should not be deleted. |
To add a Windows Forms control to the document by single-clicking the control
-
Create or open an Excel Workbook project or Word Document project in Visual Studio so that the document is visible in the designer. For information on creating projects, see How to: Create Visual Studio Tools for Office Projects.
-
In the Common Controls tab of the Toolbox, click the control you want to add
-
One the document, click where you want the control to be added.
The control is added to the document with the default size.
Note |
|---|
| When you select a control in Excel, you will see =EMBED("WinForms.Control.Host","") in the Formula Bar. This text is necessary and should not be deleted. |
To add a Windows Forms control to the document by double-clicking the control
-
Create or open an Excel Workbook project or Word Document project in Visual Studio so that the document is visible in the designer. For information on creating projects, see How to: Create Visual Studio Tools for Office Projects.
-
In the Common Controls tab of the Toolbox, double-click the control you want to add.
The control is added to the document at the center of the document or active pane.
Note |
|---|
| When you select a control in Excel, you will see =EMBED("WinForms.Control.Host","") in the Formula Bar. This text is necessary and should not be deleted. |
To add a Windows Forms control to the document by pressing the ENTER key
-
Create or open an Excel Workbook project or Word Document project in Visual Studio so that the document is visible in the designer. For information on creating projects, see How to: Create Visual Studio Tools for Office Projects.
-
In the Common Controls tab of the Toolbox, click the control you want to add, and press the ENTER key.
The control is added to the document at the center of the document or active pane.
Note |
|---|
| When you select a control in Excel, you will see =EMBED("WinForms.Control.Host","") in the Formula Bar. This text is necessary and should not be deleted. |
You can also add Windows Forms controls dynamically to a document at run time using the helper methods provided by Microsoft Visual Studio 2005 Tools for the Microsoft Office System. In the example below, a Button is added to cell A1 of an Excel Application project. For information on adding other Windows Forms controls, see Adding Controls to Office Documents at Run Time.
Adding Controls at Run Time
To add a Windows Forms control programmatically
See Also