首页 > 其他 > 详细

通过反射绑定事件_Office Visio

时间:2014-04-04 05:57:30      阅读:471      评论:0      收藏:0      [点我收藏+]

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

通过反射绑定事件_Office Visio,布布扣,bubuko.com

通过反射绑定事件_Office Visio

原文:http://www.cnblogs.com/fjwuyongzhi/p/3642947.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!