转自:Cad人生
链接:http://www.cnblogs.com/cadlife/p/3463337.html
内容粘贴如下:
主要是绑定两个事件:一个是 Application.DocumentManager.DocumentLockModeChanged ----- 该事件为文档锁定事件,一直在被监测中
一个是 Application.BeginDoubleClick ----- 该事件为应用程序的双击事件
1 class TlsApplication : IExtensionApplication //程序初始化,在加载dll时,cad会自动捕捉并运行该过程
3 { 5 void IExtensionApplication.Initialize() 7 { 9 TTest.Start(); 11 } 13 void IExtensionApplication.Terminate() 15 { 17 } 19 } 20 21 class TTest 23 { 25 static bool m_Veto = false; 27 public static void Start() 29 { 31 Application.DocumentManager.DocumentLockModeChanged += new DocumentLockModeChangedEventHandler(vetoCommand); 33 Application.BeginDoubleClick += new BeginDoubleClickEventHandler(beginDoubleClick); 35 } 37 static void beginDoubleClick(object sender, BeginDoubleClickEventArgs e) 39 { 41 Document doc = Application.DocumentManager.MdiActiveDocument; 43 Editor ed = doc.Editor; 45 PromptSelectionResult res = ed.SelectImplied(); 47 SelectionSet ss = res.Value; 49 if (ss != null) 51 { 53 if (ss.Count == 1) 55 { 57 using (Transaction tr = doc.TransactionManager.StartTransaction()) 59 { 61 Line line = tr.GetObject(ss[0].ObjectId, OpenMode.ForRead) as Line; 63 if (line != null) 65 { 67 ResultBuffer rb = line.GetXDataForApplication("MyApp"); //提取对象的扩展数据 69 if (rb != null) 71 { 73 m_Veto = true; 75 } 77 } 79 } 81 } 83 } 85 } 86 87 static void vetoCommand(object sender, DocumentLockModeChangedEventArgs e) 89 { 91 if (e.GlobalCommandName.ToLower() == "properties") //判断是否是调用属性对话框 93 { 95 if (m_Veto) 97 { 99 e.Veto(); 103 Application.ShowAlertDialog("hello"); //在此处可以添加自定义对话框 105 m_Veto = false; 107 } 109 } 111 } 113 }