Windows Forms 2.0 Enhancements

Post on 24-May-2015

1.242 views 0 download

Tags:

Transcript of Windows Forms 2.0 Enhancements

Visual Basic 2005 and Windows Forms 2.0 EnhancementsVisual Basic 2005 and Windows Forms 2.0 Enhancements

Tyler WhitneyTyler Whitney

Microsoft, CorpMicrosoft, Corp

Visual Studio 2005 Smart Client GoalsVisual Studio 2005 Smart Client Goals

Bring the ease and reliability of web Bring the ease and reliability of web application deployment to client application deployment to client applicationsapplications

Professional Look and FeelProfessional Look and FeelNew controls and enhancementsNew controls and enhancements

Continued investment in developer Continued investment in developer productivityproductivity

Simplify working with dataSimplify working with data

Fewer lines of code for common tasksFewer lines of code for common tasks

Data Sources Window, Drag and drop operationsData Sources Window, Drag and drop operations

Dragging/dropping tables from Data Dragging/dropping tables from Data Sources Window onto form will create Sources Window onto form will create instances of:instances of:

DataSet, TableAdapter, BindingSourceDataSet, TableAdapter, BindingSourceBindingNavigator with nav/add/delete/save BindingNavigator with nav/add/delete/save controlscontrolsBound control(s)Bound control(s)

Use Data Sources window to Use Data Sources window to configure:configure:

Whether table will be edited with DataGridView Whether table will be edited with DataGridView or or ““DetailsDetails”” mode (individual controls) mode (individual controls)Mapping of detail control types to column data Mapping of detail control types to column data types (shortcut to Windows Forms types (shortcut to Windows Forms Designer/Data UI Customization node in Designer/Data UI Customization node in Options dialog)Options dialog)

How It All ConnectsHow It All Connects

Bin

din

gS

ou

rce

Bin

din

gS

ou

rce

Dat

aSet

Dat

aSet

Dat

aTab

leD

ataT

able

DataSourceDataSource

SimpleSimpleControlControl

DataBindingDataBinding

PropertyProperty

Changes Changes control control

contents via contents via navigation, navigation,

maintenancemaintenanceBin

din

gN

avig

ato

rB

ind

ing

Nav

igat

or

BindingSourceBindingSource

SummarySummary

IDE SettingsIDE Settings

Winform ControlsWinform Controls

ResourcesResources

Application EventsApplication Events

Code RefactoringCode Refactoring

Data design-time enhancementsData design-time enhancements

ClickOnce DeploymentClickOnce Deployment

RegFree COMRegFree COM

Lookup BindingLookup Binding

Using the Actions Pane, Host Controls, and Smart Tags

Using the Actions Pane, Host Controls, and Smart Tags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI Enables contextual UI complementary to the documentcomplementary to the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleActions PaneCreate a SimpleActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions Add multiple controls to the actions panepane

Change the stack order of controls on Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions panethe orientation of the actions pane

Programmatically change the Programmatically change the orientation of the actions paneorientation of the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control LayoutManaging Control Layout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host A type that extends the host application (Word or Excel) Object application (Word or Excel) Object Model to provide Model to provide new functionalitynew functionality or or to to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel without Host ControlsAutomating Excel without Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host ControlsCreating Excel Host Controls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host ControlsUsing Excel Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host ControlsCreating Word Host Controls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host ControlsUsing Bookmark Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel added to the Word or Excel document at runtime document at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic Controls

Controls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of Create dynamic controls with methods of the Controls collectionthe Controls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Using the Actions Pane, Host Controls, and Smart Tags

Using the Actions Pane, Host Controls, and Smart Tags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI Enables contextual UI complementary to the documentcomplementary to the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleActions PaneCreate a SimpleActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions Add multiple controls to the actions panepane

Change the stack order of controls on Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions panethe orientation of the actions pane

Programmatically change the Programmatically change the orientation of the actions paneorientation of the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control LayoutManaging Control Layout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host A type that extends the host application (Word or Excel) Object application (Word or Excel) Object Model to provide Model to provide new functionalitynew functionality or or to to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel without Host ControlsAutomating Excel without Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host ControlsCreating Excel Host Controls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host ControlsUsing Excel Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host ControlsCreating Word Host Controls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host ControlsUsing Bookmark Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel added to the Word or Excel document at runtime document at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic Controls

Controls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of Create dynamic controls with methods of the Controls collectionthe Controls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Using the Actions Pane, Host Controls, and Smart Tags

Using the Actions Pane, Host Controls, and Smart Tags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI Enables contextual UI complementary to the documentcomplementary to the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleActions PaneCreate a SimpleActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions Add multiple controls to the actions panepane

Change the stack order of controls on Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions panethe orientation of the actions pane

Programmatically change the Programmatically change the orientation of the actions paneorientation of the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control LayoutManaging Control Layout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host A type that extends the host application (Word or Excel) Object application (Word or Excel) Object Model to provide Model to provide new functionalitynew functionality or or to to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel without Host ControlsAutomating Excel without Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host ControlsCreating Excel Host Controls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host ControlsUsing Excel Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host ControlsCreating Word Host Controls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host ControlsUsing Bookmark Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel added to the Word or Excel document at runtime document at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic Controls

Controls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of Create dynamic controls with methods of the Controls collectionthe Controls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Using the Actions Pane, Host Controls, and Smart Tags

Using the Actions Pane, Host Controls, and Smart Tags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI Enables contextual UI complementary to the documentcomplementary to the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleActions PaneCreate a SimpleActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions Add multiple controls to the actions panepane

Change the stack order of controls on Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions panethe orientation of the actions pane

Programmatically change the Programmatically change the orientation of the actions paneorientation of the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control LayoutManaging Control Layout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host A type that extends the host application (Word or Excel) Object application (Word or Excel) Object Model to provide Model to provide new functionalitynew functionality or or to to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel without Host ControlsAutomating Excel without Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host ControlsCreating Excel Host Controls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host ControlsUsing Excel Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host ControlsCreating Word Host Controls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host ControlsUsing Bookmark Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel added to the Word or Excel document at runtime document at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic Controls

Controls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of Create dynamic controls with methods of the Controls collectionthe Controls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Visual Basic 2005 and Windows Forms 2.0 EnhancementsVisual Basic 2005 and Windows Forms 2.0 Enhancements

Tyler WhitneyTyler Whitney

Microsoft, CorpMicrosoft, Corp

Visual Studio 2005 Smart Client GoalsVisual Studio 2005 Smart Client Goals

Bring the ease and reliability of web Bring the ease and reliability of web application deployment to client application deployment to client applicationsapplications

Professional Look and FeelProfessional Look and FeelNew controls and enhancementsNew controls and enhancements

Continued investment in developer Continued investment in developer productivityproductivity

Simplify working with dataSimplify working with data

Fewer lines of code for common tasksFewer lines of code for common tasks

Data Sources Window, Drag and drop operationsData Sources Window, Drag and drop operations

Dragging/dropping tables from Data Dragging/dropping tables from Data Sources Window onto form will create Sources Window onto form will create instances of:instances of:

DataSet, TableAdapter, BindingSourceDataSet, TableAdapter, BindingSourceBindingNavigator with nav/add/delete/save BindingNavigator with nav/add/delete/save controlscontrolsBound control(s)Bound control(s)

Use Data Sources window to Use Data Sources window to configure:configure:

Whether table will be edited with DataGridView Whether table will be edited with DataGridView or or ““DetailsDetails”” mode (individual controls) mode (individual controls)Mapping of detail control types to column data Mapping of detail control types to column data types (shortcut to Windows Forms types (shortcut to Windows Forms Designer/Data UI Customization node in Designer/Data UI Customization node in Options dialog)Options dialog)

How It All ConnectsHow It All Connects

Bin

din

gS

ou

rce

Bin

din

gS

ou

rce

Dat

aSet

Dat

aSet

Dat

aTab

leD

ataT

able

DataSourceDataSource

SimpleSimpleControlControl

DataBindingDataBinding

PropertyProperty

Changes Changes control control

contents via contents via navigation, navigation,

maintenancemaintenanceBin

din

gN

avig

ato

rB

ind

ing

Nav

igat

or

BindingSourceBindingSource

SummarySummary

IDE SettingsIDE Settings

Winform ControlsWinform Controls

ResourcesResources

Application EventsApplication Events

Code RefactoringCode Refactoring

Data design-time enhancementsData design-time enhancements

ClickOnce DeploymentClickOnce Deployment

RegFree COMRegFree COM

Lookup BindingLookup Binding

Using the Actions Pane, Host Controls, and Smart Tags

Using the Actions Pane, Host Controls, and Smart Tags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI Enables contextual UI complementary to the documentcomplementary to the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleActions PaneCreate a SimpleActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions Add multiple controls to the actions panepane

Change the stack order of controls on Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions panethe orientation of the actions pane

Programmatically change the Programmatically change the orientation of the actions paneorientation of the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control LayoutManaging Control Layout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host A type that extends the host application (Word or Excel) Object application (Word or Excel) Object Model to provide Model to provide new functionalitynew functionality or or to to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel without Host ControlsAutomating Excel without Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host ControlsCreating Excel Host Controls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host ControlsUsing Excel Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host ControlsCreating Word Host Controls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host ControlsUsing Bookmark Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel added to the Word or Excel document at runtime document at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic Controls

Controls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of Create dynamic controls with methods of the Controls collectionthe Controls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Using the Actions Pane, Host Controls, and Smart Tags

Using the Actions Pane, Host Controls, and Smart Tags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI Enables contextual UI complementary to the documentcomplementary to the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleActions PaneCreate a SimpleActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions Add multiple controls to the actions panepane

Change the stack order of controls on Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions panethe orientation of the actions pane

Programmatically change the Programmatically change the orientation of the actions paneorientation of the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control LayoutManaging Control Layout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host A type that extends the host application (Word or Excel) Object application (Word or Excel) Object Model to provide Model to provide new functionalitynew functionality or or to to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel without Host ControlsAutomating Excel without Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host ControlsCreating Excel Host Controls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host ControlsUsing Excel Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host ControlsCreating Word Host Controls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host ControlsUsing Bookmark Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel added to the Word or Excel document at runtime document at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic Controls

Controls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of Create dynamic controls with methods of the Controls collectionthe Controls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Using the Actions Pane, Host Controls, and Smart Tags

Using the Actions Pane, Host Controls, and Smart Tags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI Enables contextual UI complementary to the documentcomplementary to the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleActions PaneCreate a SimpleActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions Add multiple controls to the actions panepane

Change the stack order of controls on Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions panethe orientation of the actions pane

Programmatically change the Programmatically change the orientation of the actions paneorientation of the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control LayoutManaging Control Layout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host A type that extends the host application (Word or Excel) Object application (Word or Excel) Object Model to provide Model to provide new functionalitynew functionality or or to to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel without Host ControlsAutomating Excel without Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host ControlsCreating Excel Host Controls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host ControlsUsing Excel Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host ControlsCreating Word Host Controls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host ControlsUsing Bookmark Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel added to the Word or Excel document at runtime document at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic Controls

Controls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of Create dynamic controls with methods of the Controls collectionthe Controls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Using the Actions Pane, Host Controls, and Smart Tags

Using the Actions Pane, Host Controls, and Smart Tags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI Enables contextual UI complementary to the documentcomplementary to the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleActions PaneCreate a SimpleActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions Add multiple controls to the actions panepane

Change the stack order of controls on Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions panethe orientation of the actions pane

Programmatically change the Programmatically change the orientation of the actions paneorientation of the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control LayoutManaging Control Layout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host A type that extends the host application (Word or Excel) Object application (Word or Excel) Object Model to provide Model to provide new functionalitynew functionality or or to to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel without Host ControlsAutomating Excel without Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host ControlsCreating Excel Host Controls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host ControlsUsing Excel Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host ControlsCreating Word Host Controls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host ControlsUsing Bookmark Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel added to the Word or Excel document at runtime document at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic Controls

Controls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of Create dynamic controls with methods of the Controls collectionthe Controls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Visual Basic 2005 and Windows Forms 2.0 EnhancementsVisual Basic 2005 and Windows Forms 2.0 Enhancements

Tyler WhitneyTyler Whitney

Microsoft, CorpMicrosoft, Corp

Visual Studio 2005 Smart Client GoalsVisual Studio 2005 Smart Client Goals

Bring the ease and reliability of web Bring the ease and reliability of web application deployment to client application deployment to client applicationsapplications

Professional Look and FeelProfessional Look and FeelNew controls and enhancementsNew controls and enhancements

Continued investment in developer Continued investment in developer productivityproductivity

Simplify working with dataSimplify working with data

Fewer lines of code for common tasksFewer lines of code for common tasks

Data Sources Window, Drag and drop operationsData Sources Window, Drag and drop operations

Dragging/dropping tables from Data Dragging/dropping tables from Data Sources Window onto form will create Sources Window onto form will create instances of:instances of:

DataSet, TableAdapter, BindingSourceDataSet, TableAdapter, BindingSourceBindingNavigator with nav/add/delete/save BindingNavigator with nav/add/delete/save controlscontrolsBound control(s)Bound control(s)

Use Data Sources window to Use Data Sources window to configure:configure:

Whether table will be edited with DataGridView Whether table will be edited with DataGridView or or ““DetailsDetails”” mode (individual controls) mode (individual controls)Mapping of detail control types to column data Mapping of detail control types to column data types (shortcut to Windows Forms types (shortcut to Windows Forms Designer/Data UI Customization node in Designer/Data UI Customization node in Options dialog)Options dialog)

How It All ConnectsHow It All Connects

Bin

din

gS

ou

rce

Bin

din

gS

ou

rce

Dat

aSet

Dat

aSet

Dat

aTab

leD

ataT

able

DataSourceDataSource

SimpleSimpleControlControl

DataBindingDataBinding

PropertyProperty

Changes Changes control control

contents via contents via navigation, navigation,

maintenancemaintenanceBin

din

gN

avig

ato

rB

ind

ing

Nav

igat

or

BindingSourceBindingSource

SummarySummary

IDE SettingsIDE Settings

Winform ControlsWinform Controls

ResourcesResources

Application EventsApplication Events

Code RefactoringCode Refactoring

Data design-time enhancementsData design-time enhancements

ClickOnce DeploymentClickOnce Deployment

RegFree COMRegFree COM

Lookup BindingLookup Binding

Using the Actions Pane, Host Controls, and Smart Tags

Using the Actions Pane, Host Controls, and Smart Tags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI Enables contextual UI complementary to the documentcomplementary to the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleActions PaneCreate a SimpleActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions Add multiple controls to the actions panepane

Change the stack order of controls on Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions panethe orientation of the actions pane

Programmatically change the Programmatically change the orientation of the actions paneorientation of the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control LayoutManaging Control Layout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host A type that extends the host application (Word or Excel) Object application (Word or Excel) Object Model to provide Model to provide new functionalitynew functionality or or to to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel without Host ControlsAutomating Excel without Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host ControlsCreating Excel Host Controls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host ControlsUsing Excel Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host ControlsCreating Word Host Controls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host ControlsUsing Bookmark Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel added to the Word or Excel document at runtime document at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic Controls

Controls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of Create dynamic controls with methods of the Controls collectionthe Controls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Using the Actions Pane, Host Controls, and Smart Tags

Using the Actions Pane, Host Controls, and Smart Tags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI Enables contextual UI complementary to the documentcomplementary to the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleActions PaneCreate a SimpleActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions Add multiple controls to the actions panepane

Change the stack order of controls on Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions panethe orientation of the actions pane

Programmatically change the Programmatically change the orientation of the actions paneorientation of the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control LayoutManaging Control Layout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host A type that extends the host application (Word or Excel) Object application (Word or Excel) Object Model to provide Model to provide new functionalitynew functionality or or to to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel without Host ControlsAutomating Excel without Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host ControlsCreating Excel Host Controls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host ControlsUsing Excel Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host ControlsCreating Word Host Controls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host ControlsUsing Bookmark Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel added to the Word or Excel document at runtime document at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic Controls

Controls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of Create dynamic controls with methods of the Controls collectionthe Controls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Using the Actions Pane, Host Controls, and Smart Tags

Using the Actions Pane, Host Controls, and Smart Tags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI Enables contextual UI complementary to the documentcomplementary to the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleActions PaneCreate a SimpleActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions Add multiple controls to the actions panepane

Change the stack order of controls on Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions panethe orientation of the actions pane

Programmatically change the Programmatically change the orientation of the actions paneorientation of the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control LayoutManaging Control Layout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host A type that extends the host application (Word or Excel) Object application (Word or Excel) Object Model to provide Model to provide new functionalitynew functionality or or to to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel without Host ControlsAutomating Excel without Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host ControlsCreating Excel Host Controls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host ControlsUsing Excel Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host ControlsCreating Word Host Controls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host ControlsUsing Bookmark Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel added to the Word or Excel document at runtime document at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic Controls

Controls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of Create dynamic controls with methods of the Controls collectionthe Controls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Using the Actions Pane, Host Controls, and Smart Tags

Using the Actions Pane, Host Controls, and Smart Tags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI Enables contextual UI complementary to the documentcomplementary to the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleActions PaneCreate a SimpleActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions Add multiple controls to the actions panepane

Change the stack order of controls on Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions panethe orientation of the actions pane

Programmatically change the Programmatically change the orientation of the actions paneorientation of the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control LayoutManaging Control Layout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host A type that extends the host application (Word or Excel) Object application (Word or Excel) Object Model to provide Model to provide new functionalitynew functionality or or to to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel without Host ControlsAutomating Excel without Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host ControlsCreating Excel Host Controls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host ControlsUsing Excel Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host ControlsCreating Word Host Controls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host ControlsUsing Bookmark Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel added to the Word or Excel document at runtime document at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic Controls

Controls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of Create dynamic controls with methods of the Controls collectionthe Controls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Visual Basic 2005 and Windows Forms 2.0 EnhancementsVisual Basic 2005 and Windows Forms 2.0 Enhancements

Tyler WhitneyTyler Whitney

Microsoft, CorpMicrosoft, Corp

Visual Studio 2005 Smart Client GoalsVisual Studio 2005 Smart Client Goals

Bring the ease and reliability of web Bring the ease and reliability of web application deployment to client application deployment to client applicationsapplications

Professional Look and FeelProfessional Look and FeelNew controls and enhancementsNew controls and enhancements

Continued investment in developer Continued investment in developer productivityproductivity

Simplify working with dataSimplify working with data

Fewer lines of code for common tasksFewer lines of code for common tasks

Data Sources Window, Drag and drop operationsData Sources Window, Drag and drop operations

Dragging/dropping tables from Data Dragging/dropping tables from Data Sources Window onto form will create Sources Window onto form will create instances of:instances of:

DataSet, TableAdapter, BindingSourceDataSet, TableAdapter, BindingSourceBindingNavigator with nav/add/delete/save BindingNavigator with nav/add/delete/save controlscontrolsBound control(s)Bound control(s)

Use Data Sources window to Use Data Sources window to configure:configure:

Whether table will be edited with DataGridView Whether table will be edited with DataGridView or or ““DetailsDetails”” mode (individual controls) mode (individual controls)Mapping of detail control types to column data Mapping of detail control types to column data types (shortcut to Windows Forms types (shortcut to Windows Forms Designer/Data UI Customization node in Designer/Data UI Customization node in Options dialog)Options dialog)

How It All ConnectsHow It All Connects

Bin

din

gS

ou

rce

Bin

din

gS

ou

rce

Dat

aSet

Dat

aSet

Dat

aTab

leD

ataT

able

DataSourceDataSource

SimpleSimpleControlControl

DataBindingDataBinding

PropertyProperty

Changes Changes control control

contents via contents via navigation, navigation,

maintenancemaintenanceBin

din

gN

avig

ato

rB

ind

ing

Nav

igat

or

BindingSourceBindingSource

SummarySummary

IDE SettingsIDE Settings

Winform ControlsWinform Controls

ResourcesResources

Application EventsApplication Events

Code RefactoringCode Refactoring

Data design-time enhancementsData design-time enhancements

ClickOnce DeploymentClickOnce Deployment

RegFree COMRegFree COM

Lookup BindingLookup Binding

Using the Actions Pane, Host Controls, and Smart Tags

Using the Actions Pane, Host Controls, and Smart Tags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI Enables contextual UI complementary to the documentcomplementary to the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleActions PaneCreate a SimpleActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions Add multiple controls to the actions panepane

Change the stack order of controls on Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions panethe orientation of the actions pane

Programmatically change the Programmatically change the orientation of the actions paneorientation of the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control LayoutManaging Control Layout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host A type that extends the host application (Word or Excel) Object application (Word or Excel) Object Model to provide Model to provide new functionalitynew functionality or or to to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel without Host ControlsAutomating Excel without Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host ControlsCreating Excel Host Controls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host ControlsUsing Excel Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host ControlsCreating Word Host Controls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host ControlsUsing Bookmark Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel added to the Word or Excel document at runtime document at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic Controls

Controls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of Create dynamic controls with methods of the Controls collectionthe Controls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Using the Actions Pane, Host Controls, and Smart Tags

Using the Actions Pane, Host Controls, and Smart Tags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI Enables contextual UI complementary to the documentcomplementary to the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleActions PaneCreate a SimpleActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions Add multiple controls to the actions panepane

Change the stack order of controls on Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions panethe orientation of the actions pane

Programmatically change the Programmatically change the orientation of the actions paneorientation of the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control LayoutManaging Control Layout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host A type that extends the host application (Word or Excel) Object application (Word or Excel) Object Model to provide Model to provide new functionalitynew functionality or or to to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel without Host ControlsAutomating Excel without Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host ControlsCreating Excel Host Controls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host ControlsUsing Excel Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host ControlsCreating Word Host Controls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host ControlsUsing Bookmark Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel added to the Word or Excel document at runtime document at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic Controls

Controls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of Create dynamic controls with methods of the Controls collectionthe Controls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Using the Actions Pane, Host Controls, and Smart Tags

Using the Actions Pane, Host Controls, and Smart Tags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI Enables contextual UI complementary to the documentcomplementary to the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleActions PaneCreate a SimpleActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions Add multiple controls to the actions panepane

Change the stack order of controls on Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions panethe orientation of the actions pane

Programmatically change the Programmatically change the orientation of the actions paneorientation of the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control LayoutManaging Control Layout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host A type that extends the host application (Word or Excel) Object application (Word or Excel) Object Model to provide Model to provide new functionalitynew functionality or or to to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel without Host ControlsAutomating Excel without Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host ControlsCreating Excel Host Controls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host ControlsUsing Excel Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host ControlsCreating Word Host Controls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host ControlsUsing Bookmark Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel added to the Word or Excel document at runtime document at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic Controls

Controls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of Create dynamic controls with methods of the Controls collectionthe Controls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Using the Actions Pane, Host Controls, and Smart Tags

Using the Actions Pane, Host Controls, and Smart Tags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI Enables contextual UI complementary to the documentcomplementary to the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleActions PaneCreate a SimpleActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions Add multiple controls to the actions panepane

Change the stack order of controls on Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions panethe orientation of the actions pane

Programmatically change the Programmatically change the orientation of the actions paneorientation of the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control LayoutManaging Control Layout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host A type that extends the host application (Word or Excel) Object application (Word or Excel) Object Model to provide Model to provide new functionalitynew functionality or or to to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel without Host ControlsAutomating Excel without Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host ControlsCreating Excel Host Controls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host ControlsUsing Excel Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host ControlsCreating Word Host Controls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host ControlsUsing Bookmark Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel added to the Word or Excel document at runtime document at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic Controls

Controls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of Create dynamic controls with methods of the Controls collectionthe Controls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Visual Basic 2005 and Windows Forms 2.0 EnhancementsVisual Basic 2005 and Windows Forms 2.0 Enhancements

Tyler WhitneyTyler Whitney

Microsoft, CorpMicrosoft, Corp

Visual Studio 2005 Smart Client GoalsVisual Studio 2005 Smart Client Goals

Bring the ease and reliability of web Bring the ease and reliability of web application deployment to client application deployment to client applicationsapplications

Professional Look and FeelProfessional Look and FeelNew controls and enhancementsNew controls and enhancements

Continued investment in developer Continued investment in developer productivityproductivity

Simplify working with dataSimplify working with data

Fewer lines of code for common tasksFewer lines of code for common tasks

Data Sources Window, Drag and drop operationsData Sources Window, Drag and drop operations

Dragging/dropping tables from Data Dragging/dropping tables from Data Sources Window onto form will create Sources Window onto form will create instances of:instances of:

DataSet, TableAdapter, BindingSourceDataSet, TableAdapter, BindingSourceBindingNavigator with nav/add/delete/save BindingNavigator with nav/add/delete/save controlscontrolsBound control(s)Bound control(s)

Use Data Sources window to Use Data Sources window to configure:configure:

Whether table will be edited with DataGridView Whether table will be edited with DataGridView or or ““DetailsDetails”” mode (individual controls) mode (individual controls)Mapping of detail control types to column data Mapping of detail control types to column data types (shortcut to Windows Forms types (shortcut to Windows Forms Designer/Data UI Customization node in Designer/Data UI Customization node in Options dialog)Options dialog)

How It All ConnectsHow It All Connects

Bin

din

gS

ou

rce

Bin

din

gS

ou

rce

Dat

aSet

Dat

aSet

Dat

aTab

leD

ataT

able

DataSourceDataSource

SimpleSimpleControlControl

DataBindingDataBinding

PropertyProperty

Changes Changes control control

contents via contents via navigation, navigation,

maintenancemaintenanceBin

din

gN

avig

ato

rB

ind

ing

Nav

igat

or

BindingSourceBindingSource

SummarySummary

IDE SettingsIDE Settings

Winform ControlsWinform Controls

ResourcesResources

Application EventsApplication Events

Code RefactoringCode Refactoring

Data design-time enhancementsData design-time enhancements

ClickOnce DeploymentClickOnce Deployment

RegFree COMRegFree COM

Lookup BindingLookup Binding

Using the Actions Pane, Host Controls, and Smart Tags

Using the Actions Pane, Host Controls, and Smart Tags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI Enables contextual UI complementary to the documentcomplementary to the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleActions PaneCreate a SimpleActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions Add multiple controls to the actions panepane

Change the stack order of controls on Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions panethe orientation of the actions pane

Programmatically change the Programmatically change the orientation of the actions paneorientation of the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control LayoutManaging Control Layout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host A type that extends the host application (Word or Excel) Object application (Word or Excel) Object Model to provide Model to provide new functionalitynew functionality or or to to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel without Host ControlsAutomating Excel without Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host ControlsCreating Excel Host Controls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host ControlsUsing Excel Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host ControlsCreating Word Host Controls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host ControlsUsing Bookmark Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel added to the Word or Excel document at runtime document at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic Controls

Controls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of Create dynamic controls with methods of the Controls collectionthe Controls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Using the Actions Pane, Host Controls, and Smart Tags

Using the Actions Pane, Host Controls, and Smart Tags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI Enables contextual UI complementary to the documentcomplementary to the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleActions PaneCreate a SimpleActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions Add multiple controls to the actions panepane

Change the stack order of controls on Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions panethe orientation of the actions pane

Programmatically change the Programmatically change the orientation of the actions paneorientation of the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control LayoutManaging Control Layout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host A type that extends the host application (Word or Excel) Object application (Word or Excel) Object Model to provide Model to provide new functionalitynew functionality or or to to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel without Host ControlsAutomating Excel without Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host ControlsCreating Excel Host Controls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host ControlsUsing Excel Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host ControlsCreating Word Host Controls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host ControlsUsing Bookmark Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel added to the Word or Excel document at runtime document at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic Controls

Controls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of Create dynamic controls with methods of the Controls collectionthe Controls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Using the Actions Pane, Host Controls, and Smart Tags

Using the Actions Pane, Host Controls, and Smart Tags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI Enables contextual UI complementary to the documentcomplementary to the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleActions PaneCreate a SimpleActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions Add multiple controls to the actions panepane

Change the stack order of controls on Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions panethe orientation of the actions pane

Programmatically change the Programmatically change the orientation of the actions paneorientation of the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control LayoutManaging Control Layout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host A type that extends the host application (Word or Excel) Object application (Word or Excel) Object Model to provide Model to provide new functionalitynew functionality or or to to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel without Host ControlsAutomating Excel without Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host ControlsCreating Excel Host Controls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host ControlsUsing Excel Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host ControlsCreating Word Host Controls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host ControlsUsing Bookmark Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel added to the Word or Excel document at runtime document at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic Controls

Controls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of Create dynamic controls with methods of the Controls collectionthe Controls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Using the Actions Pane, Host Controls, and Smart Tags

Using the Actions Pane, Host Controls, and Smart Tags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI Enables contextual UI complementary to the documentcomplementary to the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleActions PaneCreate a SimpleActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions Add multiple controls to the actions panepane

Change the stack order of controls on Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions panethe orientation of the actions pane

Programmatically change the Programmatically change the orientation of the actions paneorientation of the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control LayoutManaging Control Layout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host A type that extends the host application (Word or Excel) Object application (Word or Excel) Object Model to provide Model to provide new functionalitynew functionality or or to to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel without Host ControlsAutomating Excel without Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host ControlsCreating Excel Host Controls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host ControlsUsing Excel Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host ControlsCreating Word Host Controls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host ControlsUsing Bookmark Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel added to the Word or Excel document at runtime document at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic Controls

Controls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of Create dynamic controls with methods of the Controls collectionthe Controls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Visual Basic 2005 and Windows Forms 2.0 EnhancementsVisual Basic 2005 and Windows Forms 2.0 Enhancements

Tyler WhitneyTyler Whitney

Microsoft, CorpMicrosoft, Corp

Visual Studio 2005 Smart Client GoalsVisual Studio 2005 Smart Client Goals

Bring the ease and reliability of web Bring the ease and reliability of web application deployment to client application deployment to client applicationsapplications

Professional Look and FeelProfessional Look and FeelNew controls and enhancementsNew controls and enhancements

Continued investment in developer Continued investment in developer productivityproductivity

Simplify working with dataSimplify working with data

Fewer lines of code for common tasksFewer lines of code for common tasks

Data Sources Window, Drag and drop operationsData Sources Window, Drag and drop operations

Dragging/dropping tables from Data Dragging/dropping tables from Data Sources Window onto form will create Sources Window onto form will create instances of:instances of:

DataSet, TableAdapter, BindingSourceDataSet, TableAdapter, BindingSourceBindingNavigator with nav/add/delete/save BindingNavigator with nav/add/delete/save controlscontrolsBound control(s)Bound control(s)

Use Data Sources window to Use Data Sources window to configure:configure:

Whether table will be edited with DataGridView Whether table will be edited with DataGridView or or ““DetailsDetails”” mode (individual controls) mode (individual controls)Mapping of detail control types to column data Mapping of detail control types to column data types (shortcut to Windows Forms types (shortcut to Windows Forms Designer/Data UI Customization node in Designer/Data UI Customization node in Options dialog)Options dialog)

How It All ConnectsHow It All Connects

Bin

din

gS

ou

rce

Bin

din

gS

ou

rce

Dat

aSet

Dat

aSet

Dat

aTab

leD

ataT

able

DataSourceDataSource

SimpleSimpleControlControl

DataBindingDataBinding

PropertyProperty

Changes Changes control control

contents via contents via navigation, navigation,

maintenancemaintenanceBin

din

gN

avig

ato

rB

ind

ing

Nav

igat

or

BindingSourceBindingSource

SummarySummary

IDE SettingsIDE Settings

Winform ControlsWinform Controls

ResourcesResources

Application EventsApplication Events

Code RefactoringCode Refactoring

Data design-time enhancementsData design-time enhancements

ClickOnce DeploymentClickOnce Deployment

RegFree COMRegFree COM

Lookup BindingLookup Binding

Using the Actions Pane, Host Controls, and Smart Tags

Using the Actions Pane, Host Controls, and Smart Tags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI Enables contextual UI complementary to the documentcomplementary to the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleActions PaneCreate a SimpleActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions Add multiple controls to the actions panepane

Change the stack order of controls on Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions panethe orientation of the actions pane

Programmatically change the Programmatically change the orientation of the actions paneorientation of the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control LayoutManaging Control Layout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host A type that extends the host application (Word or Excel) Object application (Word or Excel) Object Model to provide Model to provide new functionalitynew functionality or or to to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel without Host ControlsAutomating Excel without Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host ControlsCreating Excel Host Controls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host ControlsUsing Excel Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host ControlsCreating Word Host Controls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host ControlsUsing Bookmark Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel added to the Word or Excel document at runtime document at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic Controls

Controls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of Create dynamic controls with methods of the Controls collectionthe Controls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Using the Actions Pane, Host Controls, and Smart Tags

Using the Actions Pane, Host Controls, and Smart Tags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI Enables contextual UI complementary to the documentcomplementary to the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleActions PaneCreate a SimpleActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions Add multiple controls to the actions panepane

Change the stack order of controls on Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions panethe orientation of the actions pane

Programmatically change the Programmatically change the orientation of the actions paneorientation of the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control LayoutManaging Control Layout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host A type that extends the host application (Word or Excel) Object application (Word or Excel) Object Model to provide Model to provide new functionalitynew functionality or or to to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel without Host ControlsAutomating Excel without Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host ControlsCreating Excel Host Controls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host ControlsUsing Excel Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host ControlsCreating Word Host Controls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host ControlsUsing Bookmark Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel added to the Word or Excel document at runtime document at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic Controls

Controls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of Create dynamic controls with methods of the Controls collectionthe Controls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Using the Actions Pane, Host Controls, and Smart Tags

Using the Actions Pane, Host Controls, and Smart Tags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI Enables contextual UI complementary to the documentcomplementary to the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleActions PaneCreate a SimpleActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions Add multiple controls to the actions panepane

Change the stack order of controls on Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions panethe orientation of the actions pane

Programmatically change the Programmatically change the orientation of the actions paneorientation of the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control LayoutManaging Control Layout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host A type that extends the host application (Word or Excel) Object application (Word or Excel) Object Model to provide Model to provide new functionalitynew functionality or or to to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel without Host ControlsAutomating Excel without Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host ControlsCreating Excel Host Controls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host ControlsUsing Excel Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host ControlsCreating Word Host Controls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host ControlsUsing Bookmark Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel added to the Word or Excel document at runtime document at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic Controls

Controls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of Create dynamic controls with methods of the Controls collectionthe Controls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Using the Actions Pane, Host Controls, and Smart Tags

Using the Actions Pane, Host Controls, and Smart Tags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI Enables contextual UI complementary to the documentcomplementary to the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleActions PaneCreate a SimpleActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions Add multiple controls to the actions panepane

Change the stack order of controls on Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions panethe orientation of the actions pane

Programmatically change the Programmatically change the orientation of the actions paneorientation of the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control LayoutManaging Control Layout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host A type that extends the host application (Word or Excel) Object application (Word or Excel) Object Model to provide Model to provide new functionalitynew functionality or or to to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel without Host ControlsAutomating Excel without Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host ControlsCreating Excel Host Controls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host ControlsUsing Excel Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host ControlsCreating Word Host Controls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host ControlsUsing Bookmark Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel added to the Word or Excel document at runtime document at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic Controls

Controls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of Create dynamic controls with methods of the Controls collectionthe Controls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Dynamic Controls and Persistence Dynamic Controls and Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls may be persisted.controls may be persisted.For example:For example:

If you remove an Excel If you remove an Excel NamedRange control, the data in NamedRange control, the data in the cells remainsthe cells remains

If you delete a Bookmark control, If you delete a Bookmark control, the contents of the bookmark the contents of the bookmark remainsremains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTagsSteps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to Host Controls give you the ability to rapidly develop powerful VSTO rapidly develop powerful VSTO applications by providing:applications by providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at Add controls to documents either at design time or run timedesign time or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understandinghttp://msdn.microsoft.com/office/understanding/vsto/default.aspx/vsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understahttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxnding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxd2tx7z6d(en-us,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run TimeAdding Bookmark at Run Timeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in SolutionOutlook Task Add-in Solution