|
选择创建新模板:
点击"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) |