【发布时间】:2010-08-18 14:36:18
【问题描述】:
从 Silverlight 4 开始,很容易启动 Word 并让用户做一些事情:
dynamic word = System.Runtime.InteropServices.Automation.CreateObject("Word.Application");
word.Visible = true;
word.Documents.Open("test.doc");
MS Word 公开了一个 Quit 事件[1]。我想处理这个事件,但对于我的生活,我无法弄清楚如何。我试着这样做:
public delegate void WordQuitEventHandler(object sender, ref bool cancel);
public event WordQuitEventHandler OnQuit;
private void WordOnQuit(dynamic sender, ref bool cancel)
{
if (OnQuit != null)
{
OnQuit(this, ref cancel);
}
}
然后做
word.Quit = WordOnQuit;
或
word.Quit += WordOnQuit;
但是不能将 WordOnQuit 的委托分配给动态对象 word.Quit。那么如何捕捉这个事件呢?
[1]http://msdn.microsoft.com/en-us/library/aa211898(v=office.11).aspx
【问题讨论】:
标签: c# com delegates silverlight-4.0 event-handling