在CAD2006中,可以借用Editor的两个事件来实现鼠标的悬浮显示信息的功能,即ToolTip。这两个事件都可以实现ToolTip的功能。具体代码如下:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
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