我刚刚使用 NetOffice v1.7.3 创建了一个 Word Addin 项目来进行概念验证。
我可以看到 2 个事件(OnStartupComplete 和 OnDisconnection)已连接。
<!-- language: c# -->
public class Addin : Word.Tools.COMAddin
{
public Addin()
{
this.OnStartupComplete += new OnStartupCompleteEventHandler(Addin_OnStartupComplete);
this.OnDisconnection += new OnDisconnectionEventHandler(Addin_OnDisconnection);
}
}
你知道如何监听新文档事件、保存文档事件和关闭文档事件吗?
我在网上找到了这段代码,但无法在 NetOffice 中练习如何操作。
<!-- language: c# -->
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Microsoft.Office.Interop.Word.ApplicationEvents2_Event wdEvents2 = (Microsoft.Office.Interop.Word.ApplicationEvents2_Event) this.Application;
wdEvents2.NewDocument += new Word.ApplicationEvents2_NewDocumentEventHandler(wdEvents2_NewDocument);
}
void wdEvents2_NewDocument(Word.Document Doc)
{
MessageBox.Show("New Document Fires.", "New Document", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
提前致谢
。