Windows Forms 2.0 Enhancements

1138
Visual Basic 2005 and Windows Forms 2.0 Enhancements Tyler Whitney Tyler Whitney Microsoft, Corp Microsoft, Corp

Transcript of Windows Forms 2.0 Enhancements

Page 1: 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

Page 2: Windows Forms 2.0 Enhancements

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

Page 3: Windows Forms 2.0 Enhancements

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)

Page 4: Windows Forms 2.0 Enhancements

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

Page 5: Windows Forms 2.0 Enhancements

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

Page 6: Windows Forms 2.0 Enhancements

Lookup BindingLookup Binding

Page 7: Windows Forms 2.0 Enhancements

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

Page 8: Windows Forms 2.0 Enhancements

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

Page 9: Windows Forms 2.0 Enhancements

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

Page 10: Windows Forms 2.0 Enhancements

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

Page 11: Windows Forms 2.0 Enhancements

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)

Page 12: Windows Forms 2.0 Enhancements

Create a SimpleActions PaneCreate a SimpleActions Pane

Page 13: Windows Forms 2.0 Enhancements

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

Page 14: Windows Forms 2.0 Enhancements

Managing Control LayoutManaging Control Layout

Page 15: Windows Forms 2.0 Enhancements

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

Page 16: Windows Forms 2.0 Enhancements

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..

Page 17: Windows Forms 2.0 Enhancements

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Page 18: Windows Forms 2.0 Enhancements

Automating Excel without Host ControlsAutomating Excel without Host Controls

Page 19: Windows Forms 2.0 Enhancements

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

Page 20: Windows Forms 2.0 Enhancements

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Page 21: Windows Forms 2.0 Enhancements

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

Page 22: Windows Forms 2.0 Enhancements

Using Excel Host ControlsUsing Excel Host Controls

Page 23: Windows Forms 2.0 Enhancements

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

Page 24: Windows Forms 2.0 Enhancements

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Page 25: Windows Forms 2.0 Enhancements

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

Page 26: Windows Forms 2.0 Enhancements

Using Bookmark Host ControlsUsing Bookmark Host Controls

Page 27: Windows Forms 2.0 Enhancements

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

Page 28: Windows Forms 2.0 Enhancements

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

Page 29: Windows Forms 2.0 Enhancements

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

Page 30: Windows Forms 2.0 Enhancements

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

Page 31: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 32: Windows Forms 2.0 Enhancements

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

Page 33: Windows Forms 2.0 Enhancements

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

Page 34: Windows Forms 2.0 Enhancements

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

Page 35: Windows Forms 2.0 Enhancements

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

Page 36: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 37: Windows Forms 2.0 Enhancements

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}”));

Page 38: Windows Forms 2.0 Enhancements

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} ;

Page 39: Windows Forms 2.0 Enhancements

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}

Page 40: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 41: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 42: Windows Forms 2.0 Enhancements

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

Page 43: Windows Forms 2.0 Enhancements

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

Page 44: Windows Forms 2.0 Enhancements

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

Page 45: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 46: Windows Forms 2.0 Enhancements

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

Page 47: Windows Forms 2.0 Enhancements

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

Page 48: Windows Forms 2.0 Enhancements

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.

Page 49: Windows Forms 2.0 Enhancements

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.”;}

Page 50: Windows Forms 2.0 Enhancements

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

Page 51: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Page 52: Windows Forms 2.0 Enhancements

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

Page 53: Windows Forms 2.0 Enhancements

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

Page 54: Windows Forms 2.0 Enhancements

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

Page 55: Windows Forms 2.0 Enhancements

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

Page 56: Windows Forms 2.0 Enhancements

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)

Page 57: Windows Forms 2.0 Enhancements

Create a SimpleActions PaneCreate a SimpleActions Pane

Page 58: Windows Forms 2.0 Enhancements

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

Page 59: Windows Forms 2.0 Enhancements

Managing Control LayoutManaging Control Layout

Page 60: Windows Forms 2.0 Enhancements

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

Page 61: Windows Forms 2.0 Enhancements

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..

Page 62: Windows Forms 2.0 Enhancements

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Page 63: Windows Forms 2.0 Enhancements

Automating Excel without Host ControlsAutomating Excel without Host Controls

Page 64: Windows Forms 2.0 Enhancements

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

Page 65: Windows Forms 2.0 Enhancements

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Page 66: Windows Forms 2.0 Enhancements

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

Page 67: Windows Forms 2.0 Enhancements

Using Excel Host ControlsUsing Excel Host Controls

Page 68: Windows Forms 2.0 Enhancements

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

Page 69: Windows Forms 2.0 Enhancements

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Page 70: Windows Forms 2.0 Enhancements

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

Page 71: Windows Forms 2.0 Enhancements

Using Bookmark Host ControlsUsing Bookmark Host Controls

Page 72: Windows Forms 2.0 Enhancements

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

Page 73: Windows Forms 2.0 Enhancements

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

Page 74: Windows Forms 2.0 Enhancements

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

Page 75: Windows Forms 2.0 Enhancements

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

Page 76: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 77: Windows Forms 2.0 Enhancements

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

Page 78: Windows Forms 2.0 Enhancements

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

Page 79: Windows Forms 2.0 Enhancements

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

Page 80: Windows Forms 2.0 Enhancements

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

Page 81: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 82: Windows Forms 2.0 Enhancements

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}”));

Page 83: Windows Forms 2.0 Enhancements

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} ;

Page 84: Windows Forms 2.0 Enhancements

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}

Page 85: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 86: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 87: Windows Forms 2.0 Enhancements

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

Page 88: Windows Forms 2.0 Enhancements

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

Page 89: Windows Forms 2.0 Enhancements

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

Page 90: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 91: Windows Forms 2.0 Enhancements

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

Page 92: Windows Forms 2.0 Enhancements

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

Page 93: Windows Forms 2.0 Enhancements

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.

Page 94: Windows Forms 2.0 Enhancements

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.”;}

Page 95: Windows Forms 2.0 Enhancements

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

Page 96: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Page 97: Windows Forms 2.0 Enhancements

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

Page 98: Windows Forms 2.0 Enhancements

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

Page 99: Windows Forms 2.0 Enhancements

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

Page 100: Windows Forms 2.0 Enhancements

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

Page 101: Windows Forms 2.0 Enhancements

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)

Page 102: Windows Forms 2.0 Enhancements

Create a SimpleActions PaneCreate a SimpleActions Pane

Page 103: Windows Forms 2.0 Enhancements

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

Page 104: Windows Forms 2.0 Enhancements

Managing Control LayoutManaging Control Layout

Page 105: Windows Forms 2.0 Enhancements

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

Page 106: Windows Forms 2.0 Enhancements

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..

Page 107: Windows Forms 2.0 Enhancements

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Page 108: Windows Forms 2.0 Enhancements

Automating Excel without Host ControlsAutomating Excel without Host Controls

Page 109: Windows Forms 2.0 Enhancements

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

Page 110: Windows Forms 2.0 Enhancements

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Page 111: Windows Forms 2.0 Enhancements

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

Page 112: Windows Forms 2.0 Enhancements

Using Excel Host ControlsUsing Excel Host Controls

Page 113: Windows Forms 2.0 Enhancements

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

Page 114: Windows Forms 2.0 Enhancements

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Page 115: Windows Forms 2.0 Enhancements

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

Page 116: Windows Forms 2.0 Enhancements

Using Bookmark Host ControlsUsing Bookmark Host Controls

Page 117: Windows Forms 2.0 Enhancements

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

Page 118: Windows Forms 2.0 Enhancements

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

Page 119: Windows Forms 2.0 Enhancements

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

Page 120: Windows Forms 2.0 Enhancements

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

Page 121: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 122: Windows Forms 2.0 Enhancements

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

Page 123: Windows Forms 2.0 Enhancements

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

Page 124: Windows Forms 2.0 Enhancements

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

Page 125: Windows Forms 2.0 Enhancements

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

Page 126: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 127: Windows Forms 2.0 Enhancements

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}”));

Page 128: Windows Forms 2.0 Enhancements

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} ;

Page 129: Windows Forms 2.0 Enhancements

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}

Page 130: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 131: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 132: Windows Forms 2.0 Enhancements

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

Page 133: Windows Forms 2.0 Enhancements

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

Page 134: Windows Forms 2.0 Enhancements

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

Page 135: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 136: Windows Forms 2.0 Enhancements

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

Page 137: Windows Forms 2.0 Enhancements

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

Page 138: Windows Forms 2.0 Enhancements

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.

Page 139: Windows Forms 2.0 Enhancements

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.”;}

Page 140: Windows Forms 2.0 Enhancements

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

Page 141: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Page 142: Windows Forms 2.0 Enhancements

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

Page 143: Windows Forms 2.0 Enhancements

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

Page 144: Windows Forms 2.0 Enhancements

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

Page 145: Windows Forms 2.0 Enhancements

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

Page 146: Windows Forms 2.0 Enhancements

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)

Page 147: Windows Forms 2.0 Enhancements

Create a SimpleActions PaneCreate a SimpleActions Pane

Page 148: Windows Forms 2.0 Enhancements

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

Page 149: Windows Forms 2.0 Enhancements

Managing Control LayoutManaging Control Layout

Page 150: Windows Forms 2.0 Enhancements

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

Page 151: Windows Forms 2.0 Enhancements

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..

Page 152: Windows Forms 2.0 Enhancements

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Page 153: Windows Forms 2.0 Enhancements

Automating Excel without Host ControlsAutomating Excel without Host Controls

Page 154: Windows Forms 2.0 Enhancements

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

Page 155: Windows Forms 2.0 Enhancements

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Page 156: Windows Forms 2.0 Enhancements

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

Page 157: Windows Forms 2.0 Enhancements

Using Excel Host ControlsUsing Excel Host Controls

Page 158: Windows Forms 2.0 Enhancements

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

Page 159: Windows Forms 2.0 Enhancements

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Page 160: Windows Forms 2.0 Enhancements

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

Page 161: Windows Forms 2.0 Enhancements

Using Bookmark Host ControlsUsing Bookmark Host Controls

Page 162: Windows Forms 2.0 Enhancements

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

Page 163: Windows Forms 2.0 Enhancements

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

Page 164: Windows Forms 2.0 Enhancements

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

Page 165: Windows Forms 2.0 Enhancements

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

Page 166: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 167: Windows Forms 2.0 Enhancements

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

Page 168: Windows Forms 2.0 Enhancements

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

Page 169: Windows Forms 2.0 Enhancements

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

Page 170: Windows Forms 2.0 Enhancements

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

Page 171: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 172: Windows Forms 2.0 Enhancements

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}”));

Page 173: Windows Forms 2.0 Enhancements

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} ;

Page 174: Windows Forms 2.0 Enhancements

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}

Page 175: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 176: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 177: Windows Forms 2.0 Enhancements

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

Page 178: Windows Forms 2.0 Enhancements

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

Page 179: Windows Forms 2.0 Enhancements

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

Page 180: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 181: Windows Forms 2.0 Enhancements

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

Page 182: Windows Forms 2.0 Enhancements

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

Page 183: Windows Forms 2.0 Enhancements

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.

Page 184: Windows Forms 2.0 Enhancements

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.”;}

Page 185: Windows Forms 2.0 Enhancements

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

Page 186: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Page 187: 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

Page 188: Windows Forms 2.0 Enhancements

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

Page 189: Windows Forms 2.0 Enhancements

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)

Page 190: Windows Forms 2.0 Enhancements

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

Page 191: Windows Forms 2.0 Enhancements

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

Page 192: Windows Forms 2.0 Enhancements

Lookup BindingLookup Binding

Page 193: Windows Forms 2.0 Enhancements

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

Page 194: Windows Forms 2.0 Enhancements

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

Page 195: Windows Forms 2.0 Enhancements

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

Page 196: Windows Forms 2.0 Enhancements

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

Page 197: Windows Forms 2.0 Enhancements

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)

Page 198: Windows Forms 2.0 Enhancements

Create a SimpleActions PaneCreate a SimpleActions Pane

Page 199: Windows Forms 2.0 Enhancements

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

Page 200: Windows Forms 2.0 Enhancements

Managing Control LayoutManaging Control Layout

Page 201: Windows Forms 2.0 Enhancements

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

Page 202: Windows Forms 2.0 Enhancements

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..

Page 203: Windows Forms 2.0 Enhancements

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Page 204: Windows Forms 2.0 Enhancements

Automating Excel without Host ControlsAutomating Excel without Host Controls

Page 205: Windows Forms 2.0 Enhancements

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

Page 206: Windows Forms 2.0 Enhancements

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Page 207: Windows Forms 2.0 Enhancements

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

Page 208: Windows Forms 2.0 Enhancements

Using Excel Host ControlsUsing Excel Host Controls

Page 209: Windows Forms 2.0 Enhancements

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

Page 210: Windows Forms 2.0 Enhancements

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Page 211: Windows Forms 2.0 Enhancements

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

Page 212: Windows Forms 2.0 Enhancements

Using Bookmark Host ControlsUsing Bookmark Host Controls

Page 213: Windows Forms 2.0 Enhancements

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

Page 214: Windows Forms 2.0 Enhancements

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

Page 215: Windows Forms 2.0 Enhancements

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

Page 216: Windows Forms 2.0 Enhancements

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

Page 217: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 218: Windows Forms 2.0 Enhancements

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

Page 219: Windows Forms 2.0 Enhancements

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

Page 220: Windows Forms 2.0 Enhancements

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

Page 221: Windows Forms 2.0 Enhancements

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

Page 222: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 223: Windows Forms 2.0 Enhancements

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}”));

Page 224: Windows Forms 2.0 Enhancements

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} ;

Page 225: Windows Forms 2.0 Enhancements

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}

Page 226: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 227: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 228: Windows Forms 2.0 Enhancements

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

Page 229: Windows Forms 2.0 Enhancements

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

Page 230: Windows Forms 2.0 Enhancements

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

Page 231: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 232: Windows Forms 2.0 Enhancements

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

Page 233: Windows Forms 2.0 Enhancements

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

Page 234: Windows Forms 2.0 Enhancements

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.

Page 235: Windows Forms 2.0 Enhancements

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.”;}

Page 236: Windows Forms 2.0 Enhancements

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

Page 237: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Page 238: Windows Forms 2.0 Enhancements

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

Page 239: Windows Forms 2.0 Enhancements

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

Page 240: Windows Forms 2.0 Enhancements

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

Page 241: Windows Forms 2.0 Enhancements

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

Page 242: Windows Forms 2.0 Enhancements

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)

Page 243: Windows Forms 2.0 Enhancements

Create a SimpleActions PaneCreate a SimpleActions Pane

Page 244: Windows Forms 2.0 Enhancements

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

Page 245: Windows Forms 2.0 Enhancements

Managing Control LayoutManaging Control Layout

Page 246: Windows Forms 2.0 Enhancements

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

Page 247: Windows Forms 2.0 Enhancements

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..

Page 248: Windows Forms 2.0 Enhancements

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Page 249: Windows Forms 2.0 Enhancements

Automating Excel without Host ControlsAutomating Excel without Host Controls

Page 250: Windows Forms 2.0 Enhancements

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

Page 251: Windows Forms 2.0 Enhancements

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Page 252: Windows Forms 2.0 Enhancements

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

Page 253: Windows Forms 2.0 Enhancements

Using Excel Host ControlsUsing Excel Host Controls

Page 254: Windows Forms 2.0 Enhancements

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

Page 255: Windows Forms 2.0 Enhancements

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Page 256: Windows Forms 2.0 Enhancements

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

Page 257: Windows Forms 2.0 Enhancements

Using Bookmark Host ControlsUsing Bookmark Host Controls

Page 258: Windows Forms 2.0 Enhancements

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

Page 259: Windows Forms 2.0 Enhancements

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

Page 260: Windows Forms 2.0 Enhancements

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

Page 261: Windows Forms 2.0 Enhancements

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

Page 262: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 263: Windows Forms 2.0 Enhancements

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

Page 264: Windows Forms 2.0 Enhancements

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

Page 265: Windows Forms 2.0 Enhancements

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

Page 266: Windows Forms 2.0 Enhancements

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

Page 267: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 268: Windows Forms 2.0 Enhancements

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}”));

Page 269: Windows Forms 2.0 Enhancements

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} ;

Page 270: Windows Forms 2.0 Enhancements

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}

Page 271: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 272: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 273: Windows Forms 2.0 Enhancements

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

Page 274: Windows Forms 2.0 Enhancements

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

Page 275: Windows Forms 2.0 Enhancements

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

Page 276: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 277: Windows Forms 2.0 Enhancements

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

Page 278: Windows Forms 2.0 Enhancements

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

Page 279: Windows Forms 2.0 Enhancements

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.

Page 280: Windows Forms 2.0 Enhancements

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.”;}

Page 281: Windows Forms 2.0 Enhancements

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

Page 282: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Page 283: Windows Forms 2.0 Enhancements

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

Page 284: Windows Forms 2.0 Enhancements

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

Page 285: Windows Forms 2.0 Enhancements

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

Page 286: Windows Forms 2.0 Enhancements

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

Page 287: Windows Forms 2.0 Enhancements

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)

Page 288: Windows Forms 2.0 Enhancements

Create a SimpleActions PaneCreate a SimpleActions Pane

Page 289: Windows Forms 2.0 Enhancements

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

Page 290: Windows Forms 2.0 Enhancements

Managing Control LayoutManaging Control Layout

Page 291: Windows Forms 2.0 Enhancements

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

Page 292: Windows Forms 2.0 Enhancements

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..

Page 293: Windows Forms 2.0 Enhancements

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Page 294: Windows Forms 2.0 Enhancements

Automating Excel without Host ControlsAutomating Excel without Host Controls

Page 295: Windows Forms 2.0 Enhancements

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

Page 296: Windows Forms 2.0 Enhancements

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Page 297: Windows Forms 2.0 Enhancements

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

Page 298: Windows Forms 2.0 Enhancements

Using Excel Host ControlsUsing Excel Host Controls

Page 299: Windows Forms 2.0 Enhancements

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

Page 300: Windows Forms 2.0 Enhancements

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Page 301: Windows Forms 2.0 Enhancements

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

Page 302: Windows Forms 2.0 Enhancements

Using Bookmark Host ControlsUsing Bookmark Host Controls

Page 303: Windows Forms 2.0 Enhancements

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

Page 304: Windows Forms 2.0 Enhancements

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

Page 305: Windows Forms 2.0 Enhancements

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

Page 306: Windows Forms 2.0 Enhancements

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

Page 307: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 308: Windows Forms 2.0 Enhancements

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

Page 309: Windows Forms 2.0 Enhancements

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

Page 310: Windows Forms 2.0 Enhancements

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

Page 311: Windows Forms 2.0 Enhancements

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

Page 312: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 313: Windows Forms 2.0 Enhancements

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}”));

Page 314: Windows Forms 2.0 Enhancements

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} ;

Page 315: Windows Forms 2.0 Enhancements

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}

Page 316: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 317: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 318: Windows Forms 2.0 Enhancements

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

Page 319: Windows Forms 2.0 Enhancements

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

Page 320: Windows Forms 2.0 Enhancements

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

Page 321: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 322: Windows Forms 2.0 Enhancements

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

Page 323: Windows Forms 2.0 Enhancements

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

Page 324: Windows Forms 2.0 Enhancements

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.

Page 325: Windows Forms 2.0 Enhancements

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.”;}

Page 326: Windows Forms 2.0 Enhancements

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

Page 327: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Page 328: Windows Forms 2.0 Enhancements

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

Page 329: Windows Forms 2.0 Enhancements

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

Page 330: Windows Forms 2.0 Enhancements

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

Page 331: Windows Forms 2.0 Enhancements

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

Page 332: Windows Forms 2.0 Enhancements

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)

Page 333: Windows Forms 2.0 Enhancements

Create a SimpleActions PaneCreate a SimpleActions Pane

Page 334: Windows Forms 2.0 Enhancements

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

Page 335: Windows Forms 2.0 Enhancements

Managing Control LayoutManaging Control Layout

Page 336: Windows Forms 2.0 Enhancements

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

Page 337: Windows Forms 2.0 Enhancements

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..

Page 338: Windows Forms 2.0 Enhancements

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Page 339: Windows Forms 2.0 Enhancements

Automating Excel without Host ControlsAutomating Excel without Host Controls

Page 340: Windows Forms 2.0 Enhancements

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

Page 341: Windows Forms 2.0 Enhancements

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Page 342: Windows Forms 2.0 Enhancements

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

Page 343: Windows Forms 2.0 Enhancements

Using Excel Host ControlsUsing Excel Host Controls

Page 344: Windows Forms 2.0 Enhancements

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

Page 345: Windows Forms 2.0 Enhancements

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Page 346: Windows Forms 2.0 Enhancements

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

Page 347: Windows Forms 2.0 Enhancements

Using Bookmark Host ControlsUsing Bookmark Host Controls

Page 348: Windows Forms 2.0 Enhancements

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

Page 349: Windows Forms 2.0 Enhancements

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

Page 350: Windows Forms 2.0 Enhancements

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

Page 351: Windows Forms 2.0 Enhancements

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

Page 352: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 353: Windows Forms 2.0 Enhancements

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

Page 354: Windows Forms 2.0 Enhancements

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

Page 355: Windows Forms 2.0 Enhancements

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

Page 356: Windows Forms 2.0 Enhancements

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

Page 357: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 358: Windows Forms 2.0 Enhancements

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}”));

Page 359: Windows Forms 2.0 Enhancements

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} ;

Page 360: Windows Forms 2.0 Enhancements

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}

Page 361: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 362: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 363: Windows Forms 2.0 Enhancements

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

Page 364: Windows Forms 2.0 Enhancements

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

Page 365: Windows Forms 2.0 Enhancements

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

Page 366: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 367: Windows Forms 2.0 Enhancements

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

Page 368: Windows Forms 2.0 Enhancements

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

Page 369: Windows Forms 2.0 Enhancements

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.

Page 370: Windows Forms 2.0 Enhancements

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.”;}

Page 371: Windows Forms 2.0 Enhancements

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

Page 372: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Page 373: 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

Page 374: Windows Forms 2.0 Enhancements

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

Page 375: Windows Forms 2.0 Enhancements

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)

Page 376: Windows Forms 2.0 Enhancements

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

Page 377: Windows Forms 2.0 Enhancements

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

Page 378: Windows Forms 2.0 Enhancements

Lookup BindingLookup Binding

Page 379: Windows Forms 2.0 Enhancements

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

Page 380: Windows Forms 2.0 Enhancements

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

Page 381: Windows Forms 2.0 Enhancements

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

Page 382: Windows Forms 2.0 Enhancements

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

Page 383: Windows Forms 2.0 Enhancements

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)

Page 384: Windows Forms 2.0 Enhancements

Create a SimpleActions PaneCreate a SimpleActions Pane

Page 385: Windows Forms 2.0 Enhancements

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

Page 386: Windows Forms 2.0 Enhancements

Managing Control LayoutManaging Control Layout

Page 387: Windows Forms 2.0 Enhancements

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

Page 388: Windows Forms 2.0 Enhancements

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..

Page 389: Windows Forms 2.0 Enhancements

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Page 390: Windows Forms 2.0 Enhancements

Automating Excel without Host ControlsAutomating Excel without Host Controls

Page 391: Windows Forms 2.0 Enhancements

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

Page 392: Windows Forms 2.0 Enhancements

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Page 393: Windows Forms 2.0 Enhancements

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

Page 394: Windows Forms 2.0 Enhancements

Using Excel Host ControlsUsing Excel Host Controls

Page 395: Windows Forms 2.0 Enhancements

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

Page 396: Windows Forms 2.0 Enhancements

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Page 397: Windows Forms 2.0 Enhancements

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

Page 398: Windows Forms 2.0 Enhancements

Using Bookmark Host ControlsUsing Bookmark Host Controls

Page 399: Windows Forms 2.0 Enhancements

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

Page 400: Windows Forms 2.0 Enhancements

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

Page 401: Windows Forms 2.0 Enhancements

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

Page 402: Windows Forms 2.0 Enhancements

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

Page 403: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 404: Windows Forms 2.0 Enhancements

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

Page 405: Windows Forms 2.0 Enhancements

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

Page 406: Windows Forms 2.0 Enhancements

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

Page 407: Windows Forms 2.0 Enhancements

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

Page 408: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 409: Windows Forms 2.0 Enhancements

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}”));

Page 410: Windows Forms 2.0 Enhancements

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} ;

Page 411: Windows Forms 2.0 Enhancements

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}

Page 412: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 413: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 414: Windows Forms 2.0 Enhancements

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

Page 415: Windows Forms 2.0 Enhancements

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

Page 416: Windows Forms 2.0 Enhancements

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

Page 417: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 418: Windows Forms 2.0 Enhancements

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

Page 419: Windows Forms 2.0 Enhancements

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

Page 420: Windows Forms 2.0 Enhancements

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.

Page 421: Windows Forms 2.0 Enhancements

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.”;}

Page 422: Windows Forms 2.0 Enhancements

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

Page 423: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Page 424: Windows Forms 2.0 Enhancements

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

Page 425: Windows Forms 2.0 Enhancements

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

Page 426: Windows Forms 2.0 Enhancements

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

Page 427: Windows Forms 2.0 Enhancements

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

Page 428: Windows Forms 2.0 Enhancements

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)

Page 429: Windows Forms 2.0 Enhancements

Create a SimpleActions PaneCreate a SimpleActions Pane

Page 430: Windows Forms 2.0 Enhancements

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

Page 431: Windows Forms 2.0 Enhancements

Managing Control LayoutManaging Control Layout

Page 432: Windows Forms 2.0 Enhancements

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

Page 433: Windows Forms 2.0 Enhancements

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..

Page 434: Windows Forms 2.0 Enhancements

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Page 435: Windows Forms 2.0 Enhancements

Automating Excel without Host ControlsAutomating Excel without Host Controls

Page 436: Windows Forms 2.0 Enhancements

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

Page 437: Windows Forms 2.0 Enhancements

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Page 438: Windows Forms 2.0 Enhancements

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

Page 439: Windows Forms 2.0 Enhancements

Using Excel Host ControlsUsing Excel Host Controls

Page 440: Windows Forms 2.0 Enhancements

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

Page 441: Windows Forms 2.0 Enhancements

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Page 442: Windows Forms 2.0 Enhancements

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

Page 443: Windows Forms 2.0 Enhancements

Using Bookmark Host ControlsUsing Bookmark Host Controls

Page 444: Windows Forms 2.0 Enhancements

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

Page 445: Windows Forms 2.0 Enhancements

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

Page 446: Windows Forms 2.0 Enhancements

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

Page 447: Windows Forms 2.0 Enhancements

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

Page 448: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 449: Windows Forms 2.0 Enhancements

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

Page 450: Windows Forms 2.0 Enhancements

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

Page 451: Windows Forms 2.0 Enhancements

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

Page 452: Windows Forms 2.0 Enhancements

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

Page 453: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 454: Windows Forms 2.0 Enhancements

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}”));

Page 455: Windows Forms 2.0 Enhancements

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} ;

Page 456: Windows Forms 2.0 Enhancements

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}

Page 457: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 458: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 459: Windows Forms 2.0 Enhancements

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

Page 460: Windows Forms 2.0 Enhancements

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

Page 461: Windows Forms 2.0 Enhancements

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

Page 462: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 463: Windows Forms 2.0 Enhancements

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

Page 464: Windows Forms 2.0 Enhancements

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

Page 465: Windows Forms 2.0 Enhancements

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.

Page 466: Windows Forms 2.0 Enhancements

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.”;}

Page 467: Windows Forms 2.0 Enhancements

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

Page 468: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Page 469: Windows Forms 2.0 Enhancements

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

Page 470: Windows Forms 2.0 Enhancements

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

Page 471: Windows Forms 2.0 Enhancements

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

Page 472: Windows Forms 2.0 Enhancements

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

Page 473: Windows Forms 2.0 Enhancements

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)

Page 474: Windows Forms 2.0 Enhancements

Create a SimpleActions PaneCreate a SimpleActions Pane

Page 475: Windows Forms 2.0 Enhancements

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

Page 476: Windows Forms 2.0 Enhancements

Managing Control LayoutManaging Control Layout

Page 477: Windows Forms 2.0 Enhancements

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

Page 478: Windows Forms 2.0 Enhancements

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..

Page 479: Windows Forms 2.0 Enhancements

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Page 480: Windows Forms 2.0 Enhancements

Automating Excel without Host ControlsAutomating Excel without Host Controls

Page 481: Windows Forms 2.0 Enhancements

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

Page 482: Windows Forms 2.0 Enhancements

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Page 483: Windows Forms 2.0 Enhancements

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

Page 484: Windows Forms 2.0 Enhancements

Using Excel Host ControlsUsing Excel Host Controls

Page 485: Windows Forms 2.0 Enhancements

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

Page 486: Windows Forms 2.0 Enhancements

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Page 487: Windows Forms 2.0 Enhancements

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

Page 488: Windows Forms 2.0 Enhancements

Using Bookmark Host ControlsUsing Bookmark Host Controls

Page 489: Windows Forms 2.0 Enhancements

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

Page 490: Windows Forms 2.0 Enhancements

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

Page 491: Windows Forms 2.0 Enhancements

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

Page 492: Windows Forms 2.0 Enhancements

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

Page 493: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 494: Windows Forms 2.0 Enhancements

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

Page 495: Windows Forms 2.0 Enhancements

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

Page 496: Windows Forms 2.0 Enhancements

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

Page 497: Windows Forms 2.0 Enhancements

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

Page 498: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 499: Windows Forms 2.0 Enhancements

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}”));

Page 500: Windows Forms 2.0 Enhancements

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} ;

Page 501: Windows Forms 2.0 Enhancements

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}

Page 502: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 503: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 504: Windows Forms 2.0 Enhancements

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

Page 505: Windows Forms 2.0 Enhancements

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

Page 506: Windows Forms 2.0 Enhancements

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

Page 507: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 508: Windows Forms 2.0 Enhancements

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

Page 509: Windows Forms 2.0 Enhancements

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

Page 510: Windows Forms 2.0 Enhancements

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.

Page 511: Windows Forms 2.0 Enhancements

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.”;}

Page 512: Windows Forms 2.0 Enhancements

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

Page 513: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Page 514: Windows Forms 2.0 Enhancements

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

Page 515: Windows Forms 2.0 Enhancements

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

Page 516: Windows Forms 2.0 Enhancements

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

Page 517: Windows Forms 2.0 Enhancements

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

Page 518: Windows Forms 2.0 Enhancements

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)

Page 519: Windows Forms 2.0 Enhancements

Create a SimpleActions PaneCreate a SimpleActions Pane

Page 520: Windows Forms 2.0 Enhancements

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

Page 521: Windows Forms 2.0 Enhancements

Managing Control LayoutManaging Control Layout

Page 522: Windows Forms 2.0 Enhancements

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

Page 523: Windows Forms 2.0 Enhancements

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..

Page 524: Windows Forms 2.0 Enhancements

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Page 525: Windows Forms 2.0 Enhancements

Automating Excel without Host ControlsAutomating Excel without Host Controls

Page 526: Windows Forms 2.0 Enhancements

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

Page 527: Windows Forms 2.0 Enhancements

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Page 528: Windows Forms 2.0 Enhancements

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

Page 529: Windows Forms 2.0 Enhancements

Using Excel Host ControlsUsing Excel Host Controls

Page 530: Windows Forms 2.0 Enhancements

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

Page 531: Windows Forms 2.0 Enhancements

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Page 532: Windows Forms 2.0 Enhancements

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

Page 533: Windows Forms 2.0 Enhancements

Using Bookmark Host ControlsUsing Bookmark Host Controls

Page 534: Windows Forms 2.0 Enhancements

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

Page 535: Windows Forms 2.0 Enhancements

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

Page 536: Windows Forms 2.0 Enhancements

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

Page 537: Windows Forms 2.0 Enhancements

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

Page 538: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 539: Windows Forms 2.0 Enhancements

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

Page 540: Windows Forms 2.0 Enhancements

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

Page 541: Windows Forms 2.0 Enhancements

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

Page 542: Windows Forms 2.0 Enhancements

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

Page 543: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 544: Windows Forms 2.0 Enhancements

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}”));

Page 545: Windows Forms 2.0 Enhancements

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} ;

Page 546: Windows Forms 2.0 Enhancements

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}

Page 547: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 548: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 549: Windows Forms 2.0 Enhancements

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

Page 550: Windows Forms 2.0 Enhancements

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

Page 551: Windows Forms 2.0 Enhancements

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

Page 552: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 553: Windows Forms 2.0 Enhancements

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

Page 554: Windows Forms 2.0 Enhancements

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

Page 555: Windows Forms 2.0 Enhancements

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.

Page 556: Windows Forms 2.0 Enhancements

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.”;}

Page 557: Windows Forms 2.0 Enhancements

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

Page 558: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Page 559: 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

Page 560: Windows Forms 2.0 Enhancements

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

Page 561: Windows Forms 2.0 Enhancements

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)

Page 562: Windows Forms 2.0 Enhancements

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

Page 563: Windows Forms 2.0 Enhancements

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

Page 564: Windows Forms 2.0 Enhancements

Lookup BindingLookup Binding

Page 565: Windows Forms 2.0 Enhancements

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

Page 566: Windows Forms 2.0 Enhancements

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

Page 567: Windows Forms 2.0 Enhancements

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

Page 568: Windows Forms 2.0 Enhancements

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

Page 569: Windows Forms 2.0 Enhancements

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)

Page 570: Windows Forms 2.0 Enhancements

Create a SimpleActions PaneCreate a SimpleActions Pane

Page 571: Windows Forms 2.0 Enhancements

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

Page 572: Windows Forms 2.0 Enhancements

Managing Control LayoutManaging Control Layout

Page 573: Windows Forms 2.0 Enhancements

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

Page 574: Windows Forms 2.0 Enhancements

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..

Page 575: Windows Forms 2.0 Enhancements

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Page 576: Windows Forms 2.0 Enhancements

Automating Excel without Host ControlsAutomating Excel without Host Controls

Page 577: Windows Forms 2.0 Enhancements

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

Page 578: Windows Forms 2.0 Enhancements

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Page 579: Windows Forms 2.0 Enhancements

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

Page 580: Windows Forms 2.0 Enhancements

Using Excel Host ControlsUsing Excel Host Controls

Page 581: Windows Forms 2.0 Enhancements

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

Page 582: Windows Forms 2.0 Enhancements

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Page 583: Windows Forms 2.0 Enhancements

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

Page 584: Windows Forms 2.0 Enhancements

Using Bookmark Host ControlsUsing Bookmark Host Controls

Page 585: Windows Forms 2.0 Enhancements

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

Page 586: Windows Forms 2.0 Enhancements

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

Page 587: Windows Forms 2.0 Enhancements

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

Page 588: Windows Forms 2.0 Enhancements

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

Page 589: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 590: Windows Forms 2.0 Enhancements

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

Page 591: Windows Forms 2.0 Enhancements

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

Page 592: Windows Forms 2.0 Enhancements

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

Page 593: Windows Forms 2.0 Enhancements

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

Page 594: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 595: Windows Forms 2.0 Enhancements

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}”));

Page 596: Windows Forms 2.0 Enhancements

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} ;

Page 597: Windows Forms 2.0 Enhancements

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}

Page 598: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 599: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 600: Windows Forms 2.0 Enhancements

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

Page 601: Windows Forms 2.0 Enhancements

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

Page 602: Windows Forms 2.0 Enhancements

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

Page 603: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 604: Windows Forms 2.0 Enhancements

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

Page 605: Windows Forms 2.0 Enhancements

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

Page 606: Windows Forms 2.0 Enhancements

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.

Page 607: Windows Forms 2.0 Enhancements

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.”;}

Page 608: Windows Forms 2.0 Enhancements

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

Page 609: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Page 610: Windows Forms 2.0 Enhancements

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

Page 611: Windows Forms 2.0 Enhancements

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

Page 612: Windows Forms 2.0 Enhancements

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

Page 613: Windows Forms 2.0 Enhancements

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

Page 614: Windows Forms 2.0 Enhancements

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)

Page 615: Windows Forms 2.0 Enhancements

Create a SimpleActions PaneCreate a SimpleActions Pane

Page 616: Windows Forms 2.0 Enhancements

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

Page 617: Windows Forms 2.0 Enhancements

Managing Control LayoutManaging Control Layout

Page 618: Windows Forms 2.0 Enhancements

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

Page 619: Windows Forms 2.0 Enhancements

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..

Page 620: Windows Forms 2.0 Enhancements

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Page 621: Windows Forms 2.0 Enhancements

Automating Excel without Host ControlsAutomating Excel without Host Controls

Page 622: Windows Forms 2.0 Enhancements

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

Page 623: Windows Forms 2.0 Enhancements

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Page 624: Windows Forms 2.0 Enhancements

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

Page 625: Windows Forms 2.0 Enhancements

Using Excel Host ControlsUsing Excel Host Controls

Page 626: Windows Forms 2.0 Enhancements

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

Page 627: Windows Forms 2.0 Enhancements

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Page 628: Windows Forms 2.0 Enhancements

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

Page 629: Windows Forms 2.0 Enhancements

Using Bookmark Host ControlsUsing Bookmark Host Controls

Page 630: Windows Forms 2.0 Enhancements

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

Page 631: Windows Forms 2.0 Enhancements

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

Page 632: Windows Forms 2.0 Enhancements

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

Page 633: Windows Forms 2.0 Enhancements

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

Page 634: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 635: Windows Forms 2.0 Enhancements

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

Page 636: Windows Forms 2.0 Enhancements

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

Page 637: Windows Forms 2.0 Enhancements

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

Page 638: Windows Forms 2.0 Enhancements

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

Page 639: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 640: Windows Forms 2.0 Enhancements

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}”));

Page 641: Windows Forms 2.0 Enhancements

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} ;

Page 642: Windows Forms 2.0 Enhancements

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}

Page 643: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 644: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 645: Windows Forms 2.0 Enhancements

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

Page 646: Windows Forms 2.0 Enhancements

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

Page 647: Windows Forms 2.0 Enhancements

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

Page 648: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 649: Windows Forms 2.0 Enhancements

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

Page 650: Windows Forms 2.0 Enhancements

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

Page 651: Windows Forms 2.0 Enhancements

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.

Page 652: Windows Forms 2.0 Enhancements

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.”;}

Page 653: Windows Forms 2.0 Enhancements

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

Page 654: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Page 655: Windows Forms 2.0 Enhancements

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

Page 656: Windows Forms 2.0 Enhancements

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

Page 657: Windows Forms 2.0 Enhancements

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

Page 658: Windows Forms 2.0 Enhancements

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

Page 659: Windows Forms 2.0 Enhancements

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)

Page 660: Windows Forms 2.0 Enhancements

Create a SimpleActions PaneCreate a SimpleActions Pane

Page 661: Windows Forms 2.0 Enhancements

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

Page 662: Windows Forms 2.0 Enhancements

Managing Control LayoutManaging Control Layout

Page 663: Windows Forms 2.0 Enhancements

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

Page 664: Windows Forms 2.0 Enhancements

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..

Page 665: Windows Forms 2.0 Enhancements

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Page 666: Windows Forms 2.0 Enhancements

Automating Excel without Host ControlsAutomating Excel without Host Controls

Page 667: Windows Forms 2.0 Enhancements

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

Page 668: Windows Forms 2.0 Enhancements

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Page 669: Windows Forms 2.0 Enhancements

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

Page 670: Windows Forms 2.0 Enhancements

Using Excel Host ControlsUsing Excel Host Controls

Page 671: Windows Forms 2.0 Enhancements

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

Page 672: Windows Forms 2.0 Enhancements

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Page 673: Windows Forms 2.0 Enhancements

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

Page 674: Windows Forms 2.0 Enhancements

Using Bookmark Host ControlsUsing Bookmark Host Controls

Page 675: Windows Forms 2.0 Enhancements

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

Page 676: Windows Forms 2.0 Enhancements

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

Page 677: Windows Forms 2.0 Enhancements

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

Page 678: Windows Forms 2.0 Enhancements

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

Page 679: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 680: Windows Forms 2.0 Enhancements

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

Page 681: Windows Forms 2.0 Enhancements

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

Page 682: Windows Forms 2.0 Enhancements

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

Page 683: Windows Forms 2.0 Enhancements

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

Page 684: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 685: Windows Forms 2.0 Enhancements

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}”));

Page 686: Windows Forms 2.0 Enhancements

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} ;

Page 687: Windows Forms 2.0 Enhancements

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}

Page 688: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 689: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 690: Windows Forms 2.0 Enhancements

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

Page 691: Windows Forms 2.0 Enhancements

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

Page 692: Windows Forms 2.0 Enhancements

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

Page 693: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 694: Windows Forms 2.0 Enhancements

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

Page 695: Windows Forms 2.0 Enhancements

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

Page 696: Windows Forms 2.0 Enhancements

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.

Page 697: Windows Forms 2.0 Enhancements

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.”;}

Page 698: Windows Forms 2.0 Enhancements

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

Page 699: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Page 700: Windows Forms 2.0 Enhancements

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

Page 701: Windows Forms 2.0 Enhancements

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

Page 702: Windows Forms 2.0 Enhancements

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

Page 703: Windows Forms 2.0 Enhancements

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

Page 704: Windows Forms 2.0 Enhancements

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)

Page 705: Windows Forms 2.0 Enhancements

Create a SimpleActions PaneCreate a SimpleActions Pane

Page 706: Windows Forms 2.0 Enhancements

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

Page 707: Windows Forms 2.0 Enhancements

Managing Control LayoutManaging Control Layout

Page 708: Windows Forms 2.0 Enhancements

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

Page 709: Windows Forms 2.0 Enhancements

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..

Page 710: Windows Forms 2.0 Enhancements

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Page 711: Windows Forms 2.0 Enhancements

Automating Excel without Host ControlsAutomating Excel without Host Controls

Page 712: Windows Forms 2.0 Enhancements

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

Page 713: Windows Forms 2.0 Enhancements

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Page 714: Windows Forms 2.0 Enhancements

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

Page 715: Windows Forms 2.0 Enhancements

Using Excel Host ControlsUsing Excel Host Controls

Page 716: Windows Forms 2.0 Enhancements

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

Page 717: Windows Forms 2.0 Enhancements

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Page 718: Windows Forms 2.0 Enhancements

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

Page 719: Windows Forms 2.0 Enhancements

Using Bookmark Host ControlsUsing Bookmark Host Controls

Page 720: Windows Forms 2.0 Enhancements

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

Page 721: Windows Forms 2.0 Enhancements

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

Page 722: Windows Forms 2.0 Enhancements

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

Page 723: Windows Forms 2.0 Enhancements

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

Page 724: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 725: Windows Forms 2.0 Enhancements

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

Page 726: Windows Forms 2.0 Enhancements

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

Page 727: Windows Forms 2.0 Enhancements

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

Page 728: Windows Forms 2.0 Enhancements

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

Page 729: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 730: Windows Forms 2.0 Enhancements

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}”));

Page 731: Windows Forms 2.0 Enhancements

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} ;

Page 732: Windows Forms 2.0 Enhancements

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}

Page 733: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 734: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 735: Windows Forms 2.0 Enhancements

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

Page 736: Windows Forms 2.0 Enhancements

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

Page 737: Windows Forms 2.0 Enhancements

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

Page 738: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 739: Windows Forms 2.0 Enhancements

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

Page 740: Windows Forms 2.0 Enhancements

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

Page 741: Windows Forms 2.0 Enhancements

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.

Page 742: Windows Forms 2.0 Enhancements

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.”;}

Page 743: Windows Forms 2.0 Enhancements

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

Page 744: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Page 745: 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

Page 746: Windows Forms 2.0 Enhancements

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

Page 747: Windows Forms 2.0 Enhancements

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)

Page 748: Windows Forms 2.0 Enhancements

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

Page 749: Windows Forms 2.0 Enhancements

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

Page 750: Windows Forms 2.0 Enhancements

Lookup BindingLookup Binding

Page 751: Windows Forms 2.0 Enhancements

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

Page 752: Windows Forms 2.0 Enhancements

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

Page 753: Windows Forms 2.0 Enhancements

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

Page 754: Windows Forms 2.0 Enhancements

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

Page 755: Windows Forms 2.0 Enhancements

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)

Page 756: Windows Forms 2.0 Enhancements

Create a SimpleActions PaneCreate a SimpleActions Pane

Page 757: Windows Forms 2.0 Enhancements

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

Page 758: Windows Forms 2.0 Enhancements

Managing Control LayoutManaging Control Layout

Page 759: Windows Forms 2.0 Enhancements

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

Page 760: Windows Forms 2.0 Enhancements

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..

Page 761: Windows Forms 2.0 Enhancements

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Page 762: Windows Forms 2.0 Enhancements

Automating Excel without Host ControlsAutomating Excel without Host Controls

Page 763: Windows Forms 2.0 Enhancements

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

Page 764: Windows Forms 2.0 Enhancements

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Page 765: Windows Forms 2.0 Enhancements

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

Page 766: Windows Forms 2.0 Enhancements

Using Excel Host ControlsUsing Excel Host Controls

Page 767: Windows Forms 2.0 Enhancements

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

Page 768: Windows Forms 2.0 Enhancements

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Page 769: Windows Forms 2.0 Enhancements

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

Page 770: Windows Forms 2.0 Enhancements

Using Bookmark Host ControlsUsing Bookmark Host Controls

Page 771: Windows Forms 2.0 Enhancements

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

Page 772: Windows Forms 2.0 Enhancements

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

Page 773: Windows Forms 2.0 Enhancements

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

Page 774: Windows Forms 2.0 Enhancements

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

Page 775: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 776: Windows Forms 2.0 Enhancements

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

Page 777: Windows Forms 2.0 Enhancements

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

Page 778: Windows Forms 2.0 Enhancements

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

Page 779: Windows Forms 2.0 Enhancements

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

Page 780: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 781: Windows Forms 2.0 Enhancements

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}”));

Page 782: Windows Forms 2.0 Enhancements

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} ;

Page 783: Windows Forms 2.0 Enhancements

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}

Page 784: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 785: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 786: Windows Forms 2.0 Enhancements

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

Page 787: Windows Forms 2.0 Enhancements

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

Page 788: Windows Forms 2.0 Enhancements

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

Page 789: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 790: Windows Forms 2.0 Enhancements

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

Page 791: Windows Forms 2.0 Enhancements

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

Page 792: Windows Forms 2.0 Enhancements

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.

Page 793: Windows Forms 2.0 Enhancements

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.”;}

Page 794: Windows Forms 2.0 Enhancements

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

Page 795: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Page 796: Windows Forms 2.0 Enhancements

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

Page 797: Windows Forms 2.0 Enhancements

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

Page 798: Windows Forms 2.0 Enhancements

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

Page 799: Windows Forms 2.0 Enhancements

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

Page 800: Windows Forms 2.0 Enhancements

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)

Page 801: Windows Forms 2.0 Enhancements

Create a SimpleActions PaneCreate a SimpleActions Pane

Page 802: Windows Forms 2.0 Enhancements

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

Page 803: Windows Forms 2.0 Enhancements

Managing Control LayoutManaging Control Layout

Page 804: Windows Forms 2.0 Enhancements

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

Page 805: Windows Forms 2.0 Enhancements

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..

Page 806: Windows Forms 2.0 Enhancements

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Page 807: Windows Forms 2.0 Enhancements

Automating Excel without Host ControlsAutomating Excel without Host Controls

Page 808: Windows Forms 2.0 Enhancements

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

Page 809: Windows Forms 2.0 Enhancements

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Page 810: Windows Forms 2.0 Enhancements

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

Page 811: Windows Forms 2.0 Enhancements

Using Excel Host ControlsUsing Excel Host Controls

Page 812: Windows Forms 2.0 Enhancements

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

Page 813: Windows Forms 2.0 Enhancements

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Page 814: Windows Forms 2.0 Enhancements

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

Page 815: Windows Forms 2.0 Enhancements

Using Bookmark Host ControlsUsing Bookmark Host Controls

Page 816: Windows Forms 2.0 Enhancements

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

Page 817: Windows Forms 2.0 Enhancements

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

Page 818: Windows Forms 2.0 Enhancements

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

Page 819: Windows Forms 2.0 Enhancements

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

Page 820: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 821: Windows Forms 2.0 Enhancements

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

Page 822: Windows Forms 2.0 Enhancements

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

Page 823: Windows Forms 2.0 Enhancements

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

Page 824: Windows Forms 2.0 Enhancements

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

Page 825: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 826: Windows Forms 2.0 Enhancements

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}”));

Page 827: Windows Forms 2.0 Enhancements

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} ;

Page 828: Windows Forms 2.0 Enhancements

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}

Page 829: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 830: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 831: Windows Forms 2.0 Enhancements

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

Page 832: Windows Forms 2.0 Enhancements

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

Page 833: Windows Forms 2.0 Enhancements

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

Page 834: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 835: Windows Forms 2.0 Enhancements

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

Page 836: Windows Forms 2.0 Enhancements

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

Page 837: Windows Forms 2.0 Enhancements

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.

Page 838: Windows Forms 2.0 Enhancements

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.”;}

Page 839: Windows Forms 2.0 Enhancements

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

Page 840: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Page 841: Windows Forms 2.0 Enhancements

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

Page 842: Windows Forms 2.0 Enhancements

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

Page 843: Windows Forms 2.0 Enhancements

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

Page 844: Windows Forms 2.0 Enhancements

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

Page 845: Windows Forms 2.0 Enhancements

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)

Page 846: Windows Forms 2.0 Enhancements

Create a SimpleActions PaneCreate a SimpleActions Pane

Page 847: Windows Forms 2.0 Enhancements

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

Page 848: Windows Forms 2.0 Enhancements

Managing Control LayoutManaging Control Layout

Page 849: Windows Forms 2.0 Enhancements

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

Page 850: Windows Forms 2.0 Enhancements

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..

Page 851: Windows Forms 2.0 Enhancements

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Page 852: Windows Forms 2.0 Enhancements

Automating Excel without Host ControlsAutomating Excel without Host Controls

Page 853: Windows Forms 2.0 Enhancements

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

Page 854: Windows Forms 2.0 Enhancements

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Page 855: Windows Forms 2.0 Enhancements

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

Page 856: Windows Forms 2.0 Enhancements

Using Excel Host ControlsUsing Excel Host Controls

Page 857: Windows Forms 2.0 Enhancements

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

Page 858: Windows Forms 2.0 Enhancements

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Page 859: Windows Forms 2.0 Enhancements

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

Page 860: Windows Forms 2.0 Enhancements

Using Bookmark Host ControlsUsing Bookmark Host Controls

Page 861: Windows Forms 2.0 Enhancements

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

Page 862: Windows Forms 2.0 Enhancements

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

Page 863: Windows Forms 2.0 Enhancements

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

Page 864: Windows Forms 2.0 Enhancements

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

Page 865: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 866: Windows Forms 2.0 Enhancements

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

Page 867: Windows Forms 2.0 Enhancements

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

Page 868: Windows Forms 2.0 Enhancements

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

Page 869: Windows Forms 2.0 Enhancements

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

Page 870: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 871: Windows Forms 2.0 Enhancements

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}”));

Page 872: Windows Forms 2.0 Enhancements

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} ;

Page 873: Windows Forms 2.0 Enhancements

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}

Page 874: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 875: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 876: Windows Forms 2.0 Enhancements

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

Page 877: Windows Forms 2.0 Enhancements

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

Page 878: Windows Forms 2.0 Enhancements

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

Page 879: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 880: Windows Forms 2.0 Enhancements

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

Page 881: Windows Forms 2.0 Enhancements

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

Page 882: Windows Forms 2.0 Enhancements

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.

Page 883: Windows Forms 2.0 Enhancements

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.”;}

Page 884: Windows Forms 2.0 Enhancements

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

Page 885: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Page 886: Windows Forms 2.0 Enhancements

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

Page 887: Windows Forms 2.0 Enhancements

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

Page 888: Windows Forms 2.0 Enhancements

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

Page 889: Windows Forms 2.0 Enhancements

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

Page 890: Windows Forms 2.0 Enhancements

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)

Page 891: Windows Forms 2.0 Enhancements

Create a SimpleActions PaneCreate a SimpleActions Pane

Page 892: Windows Forms 2.0 Enhancements

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

Page 893: Windows Forms 2.0 Enhancements

Managing Control LayoutManaging Control Layout

Page 894: Windows Forms 2.0 Enhancements

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

Page 895: Windows Forms 2.0 Enhancements

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..

Page 896: Windows Forms 2.0 Enhancements

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Page 897: Windows Forms 2.0 Enhancements

Automating Excel without Host ControlsAutomating Excel without Host Controls

Page 898: Windows Forms 2.0 Enhancements

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

Page 899: Windows Forms 2.0 Enhancements

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Page 900: Windows Forms 2.0 Enhancements

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

Page 901: Windows Forms 2.0 Enhancements

Using Excel Host ControlsUsing Excel Host Controls

Page 902: Windows Forms 2.0 Enhancements

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

Page 903: Windows Forms 2.0 Enhancements

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Page 904: Windows Forms 2.0 Enhancements

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

Page 905: Windows Forms 2.0 Enhancements

Using Bookmark Host ControlsUsing Bookmark Host Controls

Page 906: Windows Forms 2.0 Enhancements

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

Page 907: Windows Forms 2.0 Enhancements

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

Page 908: Windows Forms 2.0 Enhancements

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

Page 909: Windows Forms 2.0 Enhancements

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

Page 910: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 911: Windows Forms 2.0 Enhancements

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

Page 912: Windows Forms 2.0 Enhancements

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

Page 913: Windows Forms 2.0 Enhancements

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

Page 914: Windows Forms 2.0 Enhancements

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

Page 915: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 916: Windows Forms 2.0 Enhancements

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}”));

Page 917: Windows Forms 2.0 Enhancements

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} ;

Page 918: Windows Forms 2.0 Enhancements

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}

Page 919: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 920: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 921: Windows Forms 2.0 Enhancements

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

Page 922: Windows Forms 2.0 Enhancements

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

Page 923: Windows Forms 2.0 Enhancements

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

Page 924: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 925: Windows Forms 2.0 Enhancements

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

Page 926: Windows Forms 2.0 Enhancements

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

Page 927: Windows Forms 2.0 Enhancements

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.

Page 928: Windows Forms 2.0 Enhancements

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.”;}

Page 929: Windows Forms 2.0 Enhancements

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

Page 930: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Page 931: 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

Page 932: Windows Forms 2.0 Enhancements

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

Page 933: Windows Forms 2.0 Enhancements

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)

Page 934: Windows Forms 2.0 Enhancements

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

Page 935: Windows Forms 2.0 Enhancements

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

Page 936: Windows Forms 2.0 Enhancements

Lookup BindingLookup Binding

Page 937: Windows Forms 2.0 Enhancements

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

Page 938: Windows Forms 2.0 Enhancements

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

Page 939: Windows Forms 2.0 Enhancements

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

Page 940: Windows Forms 2.0 Enhancements

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

Page 941: Windows Forms 2.0 Enhancements

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)

Page 942: Windows Forms 2.0 Enhancements

Create a SimpleActions PaneCreate a SimpleActions Pane

Page 943: Windows Forms 2.0 Enhancements

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

Page 944: Windows Forms 2.0 Enhancements

Managing Control LayoutManaging Control Layout

Page 945: Windows Forms 2.0 Enhancements

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

Page 946: Windows Forms 2.0 Enhancements

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..

Page 947: Windows Forms 2.0 Enhancements

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Page 948: Windows Forms 2.0 Enhancements

Automating Excel without Host ControlsAutomating Excel without Host Controls

Page 949: Windows Forms 2.0 Enhancements

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

Page 950: Windows Forms 2.0 Enhancements

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Page 951: Windows Forms 2.0 Enhancements

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

Page 952: Windows Forms 2.0 Enhancements

Using Excel Host ControlsUsing Excel Host Controls

Page 953: Windows Forms 2.0 Enhancements

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

Page 954: Windows Forms 2.0 Enhancements

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Page 955: Windows Forms 2.0 Enhancements

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

Page 956: Windows Forms 2.0 Enhancements

Using Bookmark Host ControlsUsing Bookmark Host Controls

Page 957: Windows Forms 2.0 Enhancements

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

Page 958: Windows Forms 2.0 Enhancements

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

Page 959: Windows Forms 2.0 Enhancements

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

Page 960: Windows Forms 2.0 Enhancements

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

Page 961: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 962: Windows Forms 2.0 Enhancements

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

Page 963: Windows Forms 2.0 Enhancements

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

Page 964: Windows Forms 2.0 Enhancements

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

Page 965: Windows Forms 2.0 Enhancements

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

Page 966: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 967: Windows Forms 2.0 Enhancements

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}”));

Page 968: Windows Forms 2.0 Enhancements

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} ;

Page 969: Windows Forms 2.0 Enhancements

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}

Page 970: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 971: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 972: Windows Forms 2.0 Enhancements

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

Page 973: Windows Forms 2.0 Enhancements

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

Page 974: Windows Forms 2.0 Enhancements

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

Page 975: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 976: Windows Forms 2.0 Enhancements

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

Page 977: Windows Forms 2.0 Enhancements

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

Page 978: Windows Forms 2.0 Enhancements

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.

Page 979: Windows Forms 2.0 Enhancements

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.”;}

Page 980: Windows Forms 2.0 Enhancements

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

Page 981: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Page 982: Windows Forms 2.0 Enhancements

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

Page 983: Windows Forms 2.0 Enhancements

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

Page 984: Windows Forms 2.0 Enhancements

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

Page 985: Windows Forms 2.0 Enhancements

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

Page 986: Windows Forms 2.0 Enhancements

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)

Page 987: Windows Forms 2.0 Enhancements

Create a SimpleActions PaneCreate a SimpleActions Pane

Page 988: Windows Forms 2.0 Enhancements

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

Page 989: Windows Forms 2.0 Enhancements

Managing Control LayoutManaging Control Layout

Page 990: Windows Forms 2.0 Enhancements

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

Page 991: Windows Forms 2.0 Enhancements

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..

Page 992: Windows Forms 2.0 Enhancements

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Page 993: Windows Forms 2.0 Enhancements

Automating Excel without Host ControlsAutomating Excel without Host Controls

Page 994: Windows Forms 2.0 Enhancements

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

Page 995: Windows Forms 2.0 Enhancements

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Page 996: Windows Forms 2.0 Enhancements

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

Page 997: Windows Forms 2.0 Enhancements

Using Excel Host ControlsUsing Excel Host Controls

Page 998: Windows Forms 2.0 Enhancements

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

Page 999: Windows Forms 2.0 Enhancements

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Page 1000: Windows Forms 2.0 Enhancements

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

Page 1001: Windows Forms 2.0 Enhancements

Using Bookmark Host ControlsUsing Bookmark Host Controls

Page 1002: Windows Forms 2.0 Enhancements

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

Page 1003: Windows Forms 2.0 Enhancements

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

Page 1004: Windows Forms 2.0 Enhancements

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

Page 1005: Windows Forms 2.0 Enhancements

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

Page 1006: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 1007: Windows Forms 2.0 Enhancements

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

Page 1008: Windows Forms 2.0 Enhancements

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

Page 1009: Windows Forms 2.0 Enhancements

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

Page 1010: Windows Forms 2.0 Enhancements

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

Page 1011: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 1012: Windows Forms 2.0 Enhancements

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}”));

Page 1013: Windows Forms 2.0 Enhancements

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} ;

Page 1014: Windows Forms 2.0 Enhancements

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}

Page 1015: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 1016: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 1017: Windows Forms 2.0 Enhancements

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

Page 1018: Windows Forms 2.0 Enhancements

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

Page 1019: Windows Forms 2.0 Enhancements

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

Page 1020: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 1021: Windows Forms 2.0 Enhancements

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

Page 1022: Windows Forms 2.0 Enhancements

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

Page 1023: Windows Forms 2.0 Enhancements

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.

Page 1024: Windows Forms 2.0 Enhancements

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.”;}

Page 1025: Windows Forms 2.0 Enhancements

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

Page 1026: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Page 1027: Windows Forms 2.0 Enhancements

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

Page 1028: Windows Forms 2.0 Enhancements

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

Page 1029: Windows Forms 2.0 Enhancements

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

Page 1030: Windows Forms 2.0 Enhancements

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

Page 1031: Windows Forms 2.0 Enhancements

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)

Page 1032: Windows Forms 2.0 Enhancements

Create a SimpleActions PaneCreate a SimpleActions Pane

Page 1033: Windows Forms 2.0 Enhancements

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

Page 1034: Windows Forms 2.0 Enhancements

Managing Control LayoutManaging Control Layout

Page 1035: Windows Forms 2.0 Enhancements

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

Page 1036: Windows Forms 2.0 Enhancements

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..

Page 1037: Windows Forms 2.0 Enhancements

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Page 1038: Windows Forms 2.0 Enhancements

Automating Excel without Host ControlsAutomating Excel without Host Controls

Page 1039: Windows Forms 2.0 Enhancements

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

Page 1040: Windows Forms 2.0 Enhancements

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Page 1041: Windows Forms 2.0 Enhancements

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

Page 1042: Windows Forms 2.0 Enhancements

Using Excel Host ControlsUsing Excel Host Controls

Page 1043: Windows Forms 2.0 Enhancements

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

Page 1044: Windows Forms 2.0 Enhancements

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Page 1045: Windows Forms 2.0 Enhancements

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

Page 1046: Windows Forms 2.0 Enhancements

Using Bookmark Host ControlsUsing Bookmark Host Controls

Page 1047: Windows Forms 2.0 Enhancements

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

Page 1048: Windows Forms 2.0 Enhancements

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

Page 1049: Windows Forms 2.0 Enhancements

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

Page 1050: Windows Forms 2.0 Enhancements

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

Page 1051: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 1052: Windows Forms 2.0 Enhancements

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

Page 1053: Windows Forms 2.0 Enhancements

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

Page 1054: Windows Forms 2.0 Enhancements

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

Page 1055: Windows Forms 2.0 Enhancements

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

Page 1056: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 1057: Windows Forms 2.0 Enhancements

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}”));

Page 1058: Windows Forms 2.0 Enhancements

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} ;

Page 1059: Windows Forms 2.0 Enhancements

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}

Page 1060: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 1061: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 1062: Windows Forms 2.0 Enhancements

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

Page 1063: Windows Forms 2.0 Enhancements

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

Page 1064: Windows Forms 2.0 Enhancements

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

Page 1065: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 1066: Windows Forms 2.0 Enhancements

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

Page 1067: Windows Forms 2.0 Enhancements

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

Page 1068: Windows Forms 2.0 Enhancements

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.

Page 1069: Windows Forms 2.0 Enhancements

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.”;}

Page 1070: Windows Forms 2.0 Enhancements

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

Page 1071: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Page 1072: Windows Forms 2.0 Enhancements

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

Page 1073: Windows Forms 2.0 Enhancements

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

Page 1074: Windows Forms 2.0 Enhancements

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

Page 1075: Windows Forms 2.0 Enhancements

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

Page 1076: Windows Forms 2.0 Enhancements

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)

Page 1077: Windows Forms 2.0 Enhancements

Create a SimpleActions PaneCreate a SimpleActions Pane

Page 1078: Windows Forms 2.0 Enhancements

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

Page 1079: Windows Forms 2.0 Enhancements

Managing Control LayoutManaging Control Layout

Page 1080: Windows Forms 2.0 Enhancements

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

Page 1081: Windows Forms 2.0 Enhancements

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..

Page 1082: Windows Forms 2.0 Enhancements

Host Control FeaturesHost Control FeaturesExtends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Page 1083: Windows Forms 2.0 Enhancements

Automating Excel without Host ControlsAutomating Excel without Host Controls

Page 1084: Windows Forms 2.0 Enhancements

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

Page 1085: Windows Forms 2.0 Enhancements

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Page 1086: Windows Forms 2.0 Enhancements

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

Page 1087: Windows Forms 2.0 Enhancements

Using Excel Host ControlsUsing Excel Host Controls

Page 1088: Windows Forms 2.0 Enhancements

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

Page 1089: Windows Forms 2.0 Enhancements

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Page 1090: Windows Forms 2.0 Enhancements

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

Page 1091: Windows Forms 2.0 Enhancements

Using Bookmark Host ControlsUsing Bookmark Host Controls

Page 1092: Windows Forms 2.0 Enhancements

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

Page 1093: Windows Forms 2.0 Enhancements

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

Page 1094: Windows Forms 2.0 Enhancements

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

Page 1095: Windows Forms 2.0 Enhancements

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

Page 1096: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 1097: Windows Forms 2.0 Enhancements

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

Page 1098: Windows Forms 2.0 Enhancements

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

Page 1099: Windows Forms 2.0 Enhancements

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

Page 1100: Windows Forms 2.0 Enhancements

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

Page 1101: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 1102: Windows Forms 2.0 Enhancements

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}”));

Page 1103: Windows Forms 2.0 Enhancements

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} ;

Page 1104: Windows Forms 2.0 Enhancements

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}

Page 1105: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 1106: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 1107: Windows Forms 2.0 Enhancements

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

Page 1108: Windows Forms 2.0 Enhancements

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

Page 1109: Windows Forms 2.0 Enhancements

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

Page 1110: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 1111: Windows Forms 2.0 Enhancements

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

Page 1112: Windows Forms 2.0 Enhancements

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

Page 1113: Windows Forms 2.0 Enhancements

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.

Page 1114: Windows Forms 2.0 Enhancements

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.”;}

Page 1115: Windows Forms 2.0 Enhancements

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

Page 1116: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution

Page 1117: Windows Forms 2.0 Enhancements

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

Page 1118: Windows Forms 2.0 Enhancements

Dynamic Host ControlsDynamic Host Controls

Page 1119: Windows Forms 2.0 Enhancements

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

Page 1120: Windows Forms 2.0 Enhancements

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

Page 1121: Windows Forms 2.0 Enhancements

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

Page 1122: Windows Forms 2.0 Enhancements

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

Page 1123: Windows Forms 2.0 Enhancements

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Page 1124: Windows Forms 2.0 Enhancements

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}”));

Page 1125: Windows Forms 2.0 Enhancements

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} ;

Page 1126: Windows Forms 2.0 Enhancements

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}

Page 1127: Windows Forms 2.0 Enhancements

Register SmartTag with DocumentRegister SmartTag with Document

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

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

Page 1128: Windows Forms 2.0 Enhancements

Smart TagsSmart Tags

Page 1129: Windows Forms 2.0 Enhancements

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

Page 1130: Windows Forms 2.0 Enhancements

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

Page 1131: Windows Forms 2.0 Enhancements

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

Page 1132: Windows Forms 2.0 Enhancements

Questions?Questions?

Page 1133: Windows Forms 2.0 Enhancements

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

Page 1134: Windows Forms 2.0 Enhancements

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

Page 1135: Windows Forms 2.0 Enhancements

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.

Page 1136: Windows Forms 2.0 Enhancements

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.”;}

Page 1137: Windows Forms 2.0 Enhancements

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

Page 1138: Windows Forms 2.0 Enhancements

Outlook Task Add-in SolutionOutlook Task Add-in Solution