花了好几个小时才Try出来,记录一下:

 

            //反射获取Visio.Application,此处没有判断是否有安装Visio
            mVisioType = System.Type.GetTypeFromProgID("Visio.Application");
            object oVisioApplication = System.Activator.CreateInstance(mVisioType);//打开Visio
            //反射获取Visio Application的Documents对象
            object oDocuments = mVisioType.InvokeMember("Documents", System.Reflection.BindingFlags.GetProperty, null, oVisioApplication, null);
            //事件
            //获取事件的下定义
            EventInfo documentOpenedEventInfo = mVisioType.GetEvent("DocumentOpened");
            MethodInfo documentOpenedMethod = this.GetType().GetMethod("DocumentOpened");//要为public,否则null

   //GetMethod("DocumentOpened")中的DocumentOpened为此类的一个方法,要为public,为private反射会null
            Delegate documentOpenedHandler = Delegate.CreateDelegate(documentOpenedEventInfo.EventHandlerType, null, documentOpenedMethod);
            documentOpenedEventInfo.AddEventHandler(oVisioApplication, documentOpenedHandler);//订阅事件

相关文章:

  • 2021-12-08
  • 2022-12-23
  • 2021-07-24
  • 2022-02-11
  • 2021-11-20
  • 2022-12-23
  • 2021-07-01
猜你喜欢
  • 2021-12-03
  • 2021-07-03
  • 2022-12-23
  • 2022-12-23
  • 2022-01-30
  • 2021-08-21
  • 2022-12-23
相关资源
相似解决方案