CAD—鼠标悬浮显示信息

    在CAD2006中,可以借用Editor的两个事件来实现鼠标的悬浮显示信息的功能,即ToolTip。这两个事件都可以实现ToolTip的功能。具体代码如下:

ExpandedBlockStart.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

转载于:https://www.cnblogs.com/wangyong/archive/2010/02/25/1673216.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值