基于Visual Studio2010开发office2010办公自动化应用(13)自定义InfoPathAddIn插件

InfoPath 2010 主要优点

通过易于使用的工具快速设计表单
使用功能区界面快速设计。传统菜单和工具栏可能需要几个步骤才能完成一项任务,而功能区以选项卡结构显示命令,按与某活动相关的任务进行组织,因此您可以快速创建需要的表单。

一键发布表单。单击功能区快速访问工具栏上的一个图标发布表单,或使用 Microsoft Office BackstageTM 视图。Backstage 视图为您提供正在执行的任务(如发布)所必不可少的信息的一个参考点。

创建 SharePoint 列表的表单。使用 InfoPath 2010,您可以通过单击基于 SharePoint 常规或外部列表的按钮创建精美的表单。如果 SharePoint 列表中有数据,则可以快速地自动生成包含所有 SharePoint 列表域的表单,然后对其进行自定义,从而缩短创建表单的时间。

使用 Microsoft SharePoint Workspace 2010(以前称为 Microsoft Office Groove 2007)完成脱机表单。可以在 Office SharePoint Workspace 界面中通过本机集成表单和数据(存储在常规或外部 SharePoint 列表中)联机或脱机填写表单。

下面来实践在InfoPath2010里面插入一个自定义的InfoPathAddIn插件,以使该InfoPathAddIn插件和InfoPath2010形成只能的交互,方便用户工作操作的便捷。

首先启动VS2010

创建一个InfoPathAddInCSDN工程

进入工程后,首先创建一个form1的窗体

在form1窗体上创建以下图示的相关控件

然后在ThisAddIn.cs里面插入下面代码

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Linq; using Visio = Microsoft.Office.Interop.Visio; using Office = Microsoft.Office.Core; namespace VisioAddInCSDN { public partial class ThisAddIn { private void ThisAddIn_Startup(object sender, System.EventArgs e) { Form1 frm = new Form1(); frm.ShowDialog(); frm.TopMost = true; } private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { } #region VSTO generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InternalStartup() { this.Startup += new System.EventHandler(ThisAddIn_Startup); this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); } #endregion } }

按下F5开始调试

运行后界面如下,InfoPath2010文档打开了以后,窗体form1也随之打开,我们可以在其上应用我们所需的各种功能: