Office中国论坛/Access中国论坛

标题: 【作业】01课-hehex [打印本页]

作者: hehex    时间: 2014-3-2 12:25
标题: 【作业】01课-hehex
本帖最后由 hehex 于 2014-3-2 12:41 编辑

还是贴代码段吧,作业都是使用word addin 完成的,没做美化。
  1. private void button1_Click(object sender, RibbonControlEventArgs e)
  2.         {
  3.             Process myProcess = new Process();
  4.             ProcessStartInfo myProInfo = new ProcessStartInfo("notepad.exe");
  5.             myProcess.StartInfo = myProInfo;
  6.             myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  7.             myProcess.Start();

  8.         }
复制代码

上面代码实现后台打开记事本。

  1. private void checkBox1_Click(object sender, RibbonControlEventArgs e)
  2.         {
  3.             if (checkBox1.Checked)
  4.             {
  5.                 Process.Start("http:\\www.office-cn.net");
  6.             }
  7.             else {
  8.                 try
  9.                 {
  10.                     Process.Start("yy://pd-[sid=91283328&subid=2175343697]");
  11.                 }
  12.                 catch (Exception)
  13.                 {
  14.                     Process.Start("http://yy.com/91283328/2175343697?from=549738578");   
  15.                     //throw;
  16.                 }        
  17.             }
  18.         }
  19.     }
  20. }
复制代码
要在using 系列语句中添加Process 的命名空间引用:
using System.Diagnostics;

上面代码实现checkbox 检查,如果选择就打开网站,如果checkbox 是未选中状态,则try catch 判断打开YY 或者网页YY。
以上代码在vs 2012 旗舰版 ,word 2013 调试通过。

谢谢老师
作者: 紫电    时间: 2014-3-7 23:30
[attach]53402[/attach]





欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3