After the control has been added to the document or spreadsheet, the experience of using the control on the design surface should be very close to that of working with a standard Windows Form. However, there are some differences. The biggest difference appears when you click a Windows Forms control in the document and use the categorized view in the Properties window. If you compare a Windows.Forms.Controls.Button with a Microsoft.Office.Tools.Excel.Controls.Button, you will see the extra properties merged in from the OLEObject. These properties are listed in the Misc category to denote that these properties are coming from OLEObject.
Excel Control Properties That Are Added from OLEObject
The OLEObject merge done for controls in the Microsoft.Office.Tools.Excel.Controls namespace adds several properties to VSTO extended controls that are not in the base Windows.Forms controls. Table 14-1 shows the most important properties that are added for controls in Excel.
Name |
Type |
Access |
Description |
---|---|---|---|
BottomRightCell |
Excel.Range |
Read-only |
The Range object that represents the cell that lies under the lower-right corner of the control. |
Enabled |
bool |
Read-write |
Determines whether the control is enabled. If you set this to false, the control will show grayed-out in Excel. This enables you to control whether the control will accept input at runtime. |
Height |
double |
Read-write |
The height, in points, of the control. |
Left |
double |
Read-write |
The distance, in points, from the left edge of the control to the left edge of column A. |
Placement |
object |
Read-write |
Determines how the control will be placed. This can be one of three values: xlFreeFloating (equivalent to Do not move or size with cell setting in the placement dialog) xlMove (equivalent to Move but do not size with cell setting in the placement dialog) xlMoveAndSize (equivalent to Move and size with cell setting in the placement dialog) |
PrintObject |
bool |
Read-write |
Determines whether the control will print when the worksheet is printed. This can prove very useful if the control you are using is something like a button that should not be part of the final printed document. |
Shadow |
bool |
Read-write |
Determines whether Excel should provide a drop shadow for the control. When set to true, Excel will provide a simple black drop shadow around the control |
TopLeftCell |
Excel.Range |
Read-only |
The Range object that represents the cell that lies under the upper-left corner of the control. |
Top |
double |
Read-write |
The distance, in points, from the top edge of the control to the top edge of row 1. |
Visible |
bool |
Read-write |
Determines whether to hide the control at runtime. |
Width |
double |
Read-write |
The width, in points, of the control. |
Word Control Properties Added from OLEControl
The OLEControl merge done for controls in the Microsoft.Office.Tools.Word.Controls namespace adds several properties to VSTO extended controls that are not in the base Windows.Forms controls. Table 14-2 shows the most important properties that are added for controls in Word.
Name |
Type |
Access |
Description |
---|---|---|---|
Bottom |
float |
Read-only |
The distance, in points, from the top edge of the first paragraph on the page to the bottom of the control |
Height |
float |
Read-write |
The height, in points, of the control |
InlineShape |
InlineShape |
Read |
Returns the InlineShape object in the Word object model corresponding to the controlreturns null if the control is not inline |
Shape |
Shape |
Read |
Returns the Shape object in the Word object model corresponding to the controlreturns null if the control is inline |
Left |
float |
Read-write |
The distance, in points, from the left edge of the control to the left edge of the first paragraph on the page |
Name |
string |
Read-write |
The name of the control |
Right |
float |
Read-only |
The distance, in points, from the right edge of the control to the left edge of the first paragraph on the page |
Top |
float |
Read-write |
The distance, in points, from the top edge of the control to the top edge of the first paragraph on the page |
Width |
float |
Read-write |
The width, in points, of the control |
Many of the properties for controls running in Word are dependent on the wrapping style of the control. If the control is inline with text, the Left, Bottom, Right, Top, and Width properties will throw an exception. Why? Word represents ActiveX controls as either Shapes or InlineShapes depending on how the control is positioned on the document, and the positioning properties are only available on Shapes that are controls whose wrapping style is Behind text or In front of text.
Word controls also have an InlineShape and Shape property that provide you with access to the InlineShape or Shape object in the Word object model corresponding to the control.
Part One. An Introduction to VSTO
An Introduction to Office Programming
Introduction to Office Solutions
Part Two. Office Programming in .NET
Programming Excel
Working with Excel Events
Working with Excel Objects
Programming Word
Working with Word Events
Working with Word Objects
Programming Outlook
Working with Outlook Events
Working with Outlook Objects
Introduction to InfoPath
Part Three. Office Programming in VSTO
The VSTO Programming Model
Using Windows Forms in VSTO
Working with Actions Pane
Working with Smart Tags in VSTO
VSTO Data Programming
Server Data Scenarios
.NET Code Security
Deployment
Part Four. Advanced Office Programming
Working with XML in Excel
Working with XML in Word
Developing COM Add-Ins for Word and Excel
Creating Outlook Add-Ins with VSTO