Asp.Net教程,WinForm教程,Asp.Net MVC,vs2008教程,vs2010教程,Silverlight技术,源码下载,Asp.Net视频教程
全站热门标签
vs2010 Silverlight 存储过程 水晶报表 ADO.NET JavaScript LINQ AjaxPro DataGridView 面向对象 Extjs GridView XML DevExpress HTML教程 Oracle jQuery 分页 Prototype教程 GDI+ Visual C++2010 MySQL Office2010 WPF MVC Dojo WCF4.0 VB.NET Sql2005 textbox cookie WCF WinForm Discuz!NT SQL经典语句 T-SQL checkbox ASPxGridView F# asp.net SQL VS2008新特性 DropDownList Access TreeView Ajax VS2008 页面执行时间 Flex 字符串 回调 VB2005 DataSet C#时间 ASP.NET性能优化 用户在线检测
当前位置: 主页 > vs2010教程 >

Visual Studio2010开发office2010办公自动化应用(5)自定义WordDocument

时间:2010-07-28 22:19来源:blog.csdn.net/yincheng01 作者:admin 点击:

选择创建新模板:

点击"OK"进入工程后,在WordDocumentCSDN.docx里插入七个button按钮,分别依次改名为:计算器、记事本、画图、写字板、注册表、CMD、设备管理器。以作为启动这些工具的快捷按钮;


 

分别双击button,插入下列代码

using System;  
using System.Collections.Generic;  
using System.Data;  
using System.Linq;  
using System.Text;  
using System.Windows.Forms;  
using System.Xml.Linq;  
using Microsoft.Office.Tools.Word;  
using Microsoft.VisualStudio.Tools.Applications.Runtime;  
using Office = Microsoft.Office.Core;  
using Word = Microsoft.Office.Interop.Word;  
using Microsoft.Win32;  
using System.Diagnostics;  
 
namespace WordDocumentCSDN  
{  
    public partial class ThisDocument  
    {  
        private void ThisDocument_Startup(object sender, System.EventArgs e)  
        {  
        }  
 
        private void ThisDocument_Shutdown(object sender, System.EventArgs e)  
        {  
        } 
 
        #region VSTO Designer 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.button2.Click += new System.EventHandler(this.button2_Click);  
            this.button3.Click += new System.EventHandler(this.button3_Click);  
            this.button7.Click += new System.EventHandler(this.button7_Click);  
            this.button1.Click += new System.EventHandler(this.button1_Click);  
            this.button4.Click += new System.EventHandler(this.button4_Click);  
            this.button5.Click += new System.EventHandler(this.button5_Click);  
            this.button6.Click += new System.EventHandler(this.button6_Click);  
            this.Startup += new System.EventHandler(this.ThisDocument_Startup);  
            this.Shutdown += new System.EventHandler(this.ThisDocument_Shutdown);  
 
        } 
 
        #endregion  
 
        private void button1_Click(object sender, EventArgs e)  
        {  
            Process.Start("calc");  
        }  
 
        private void button2_Click(object sender, EventArgs e)  
        {  
            Process.Start("notepad");  
        }  
 
        private void button3_Click(object sender, EventArgs e)  
        {  
            Process.Start("mspaint");  
        }  
 
        private void button4_Click(object sender, EventArgs e)  
        {  
            Process.Start("write");  
        }  
 
        private void button5_Click(object sender, EventArgs e)  
        {  
            Process.Start("regedit");  
        }  
 
        private void button6_Click(object sender, EventArgs e)  
        {  
            Process.Start("cmd.exe");  
        }  
 
        private void button7_Click(object sender, EventArgs e)  
        {  
            Process.Start("devmgmt.msc");  
        }  
    }  

按下F5开始调试


执行效果如下,我们的文档打开了以后,文档内嵌了包括计算器、记事本、画图、写字板、注册表、CMD、设备管理器多个按钮

在书写文档中,需要用到计算器,我们顺便点击文档中"计算器"就可以把计算器快捷呼出:

其他各功能快捷按钮用法如上所同。

 

(责任编辑:admin)
Tags:Office2010
责任编辑:admin
返回顶部
------分隔线----------------------------
推荐内容
骆驼户外男 真皮磨砂日常休闲鞋 低帮 2011秋冬新款 专柜正品特价 骆驼户外男 真皮磨砂日常休闲鞋 低帮 2011秋冬新款 专柜正品特价