悟空-简单就好
.net企业级应用研究

考虑最复杂的情况
开发出最简单的实现


Word文档-资料管理系统!

导航

 

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

posted on 2014-04-03 14:28  新悟空  阅读(346)  评论(0编辑  收藏  举报