在CAD2006中,可以借用Editor的两个事件来实现鼠标的悬浮显示信息的功能,即ToolTip。这两个事件都可以实现ToolTip的功能。具体代码如下:
代码
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
#region IExtensionApplication 成员
public void Initialize()
{
MyToolTip();
}
public void Terminate()
{
//throw new System.Exception("The method or operation is not implemented.");
}
private void MyToolTip()
{
ed.PointMonitor +=new PointMonitorEventHandler(ToolTip);
ed.PointFilter +=new PointFilterEventHandler(ed_PointFilter);
}
private void ToolTip(object sender, PointMonitorEventArgs e)
{
Database db = HostApplicationServices.WorkingDatabase;
FullSubentityPath[] paths = e.Context.GetPickedEntities();
if (paths.Length > 0)
{
FullSubentityPath fsPath = paths[0];
using (Transaction trans = db.TransactionManager.StartTransaction())
{
ObjectId entId = fsPath.GetObjectIds()[0];
Entity ent = trans.GetObject(entId, OpenMode.ForRead) as Entity;
e.AppendToolTipText("PointMonitor事件\n实体是:" + ent.GetType().ToString());
trans.Commit();
}
}
else
{
e.AppendToolTipText("请选择图元");
}
}
private void ed_PointFilter(object sender, PointFilterEventArgs e)
{
Database db = HostApplicationServices.WorkingDatabase;
FullSubentityPath[] full = e.Context.GetPickedEntities();
if (full.Length > 0)
{
FullSubentityPath fSon = full[0];
ObjectId[] ids = fSon.GetObjectIds();
ObjectId id = ids[0];
using (Transaction trans = db.TransactionManager.StartTransaction())
{
Entity ent = trans.GetObject(id, OpenMode.ForRead) as Entity;
e.Result.ToolTipText = "PointFilter事件\nID:" + id.ToString();
}
}
}
#endregion
#region IExtensionApplication 成员
public void Initialize()
{
MyToolTip();
}
public void Terminate()
{
//throw new System.Exception("The method or operation is not implemented.");
}
private void MyToolTip()
{
ed.PointMonitor +=new PointMonitorEventHandler(ToolTip);
ed.PointFilter +=new PointFilterEventHandler(ed_PointFilter);
}
private void ToolTip(object sender, PointMonitorEventArgs e)
{
Database db = HostApplicationServices.WorkingDatabase;
FullSubentityPath[] paths = e.Context.GetPickedEntities();
if (paths.Length > 0)
{
FullSubentityPath fsPath = paths[0];
using (Transaction trans = db.TransactionManager.StartTransaction())
{
ObjectId entId = fsPath.GetObjectIds()[0];
Entity ent = trans.GetObject(entId, OpenMode.ForRead) as Entity;
e.AppendToolTipText("PointMonitor事件\n实体是:" + ent.GetType().ToString());
trans.Commit();
}
}
else
{
e.AppendToolTipText("请选择图元");
}
}
private void ed_PointFilter(object sender, PointFilterEventArgs e)
{
Database db = HostApplicationServices.WorkingDatabase;
FullSubentityPath[] full = e.Context.GetPickedEntities();
if (full.Length > 0)
{
FullSubentityPath fSon = full[0];
ObjectId[] ids = fSon.GetObjectIds();
ObjectId id = ids[0];
using (Transaction trans = db.TransactionManager.StartTransaction())
{
Entity ent = trans.GetObject(id, OpenMode.ForRead) as Entity;
e.Result.ToolTipText = "PointFilter事件\nID:" + id.ToString();
}
}
}
#endregion