• 通过反射绑定事件_Office Visio


    花了好几个小时才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);//订阅事件

  • 相关阅读:
    ES6解构赋值
    ES6中的Symbol类型
    两个列表合并成字典
    python关于列表转为字典的两个小方法
    break、continue和return的使用
    进度条的实现
    md5加密
    dict字典方法
    用户相关的文件、解析以及命令的使用
    linux的根目录
  • 原文地址:https://www.cnblogs.com/fjwuyongzhi/p/3642947.html
Copyright © 2020-2023  润新知