zoukankan      html  css  js  c++  java
  • 通过反射绑定事件_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);//订阅事件

  • 相关阅读:
    (7)排序之归并排序
    (5)排序之简单选择排序
    (4)排序之希尔排序
    (3)排序之直接插入排序
    (2)排序之快速排序
    (1)排序之冒泡排序
    Python学习
    centos下docker网络桥接
    docker下搭建gitlab
    centos版本7以上网卡名修改
  • 原文地址:https://www.cnblogs.com/fjwuyongzhi/p/3642947.html
Copyright © 2011-2022 走看看