转自:Cad人生
链接:http://www.cnblogs.com/cadlife/p/3463337.html
内容粘贴如下:
主要是绑定两个事件:一个是 Application.DocumentManager.DocumentLockModeChanged ----- 该事件为文档锁定事件,一直在被监测中
一个是 Application.BeginDoubleClick ----- 该事件为应用程序的双击事件
class TlsApplication : IExtensionApplication //程序初始化,在加载dll时,cad会自动捕捉并运行该过程
{
void IExtensionApplication.Initialize()
{
TTest.Start();
}
void IExtensionApplication.Terminate()
{
}
} class TTest
{
static bool m_Veto = false;
public static void Start()
{
Application.DocumentManager.DocumentLockModeChanged += new DocumentLockModeChangedEventHandler(vetoCommand);
Application.BeginDoubleClick += new BeginDoubleClickEventHandler(beginDoubleClick);
}
static void beginDoubleClick(object sender, BeginDoubleClickEventArgs e)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
PromptSelectionResult res = ed.SelectImplied();
SelectionSet ss = res.Value;
if (ss != null)
{
if (ss.Count == )
{
using (Transaction tr = doc.TransactionManager.StartTransaction())
{
Line line = tr.GetObject(ss[].ObjectId, OpenMode.ForRead) as Line;
if (line != null)
{
ResultBuffer rb = line.GetXDataForApplication("MyApp"); //提取对象的扩展数据
if (rb != null)
{
m_Veto = true;
}
}
}
}
}
} static void vetoCommand(object sender, DocumentLockModeChangedEventArgs e)
{
if (e.GlobalCommandName.ToLower() == "properties") //判断是否是调用属性对话框
{
if (m_Veto)
{
e.Veto();
Application.ShowAlertDialog("hello"); //在此处可以添加自定义对话框
m_Veto = false;
}
}
}
}