在写PPT插件时,遇到了一个问题,如下:
......
public partial class ThisAddIn
{
private Microsoft.Office.Interop.PowerPoint.Application powerpoint_App;
......
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
......
powerpoint_App.NewPresentation += new EApplication_NewPresentationEventHandler(this.DoNewPresentation); //添加响应的委托事件
......
}
......
但是,上面那段代码编译的时候,报错了,“Eapplication_Event.NewPresentation和_Application.NewPresentation具有二义性”,尝试各种方法无法解决。
进入相关函数定义文件,发现:
EApplication_Event从元数据文件和_Application从元数据文件中:Microsoft.Office.Interop.PowerPoint空间下对应的两个接口下面都存在函数NewPresentation的定义
(1)public interface EApplication_Event
{
......
event EApplication_NewPresentationEventHandler NewPresentation;
.....
}
(2)public interface _Application
{
......
NewFile NewPresentation { get; }
......
}
那么怎样在调用时进行区分呢,修改为如下语句即可:
(powerpoint_App as EApplication_Event).NewPresentation += new EApplication_NewPresentationEventHandler(this.DoNewPresentation);