明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 7711|回复: 11

[事件] tooltip显示图元类型

[复制链接]
发表于 2009-6-4 19:10 | 显示全部楼层 |阅读模式
  1. using Autodesk.AutoCAD.ApplicationServices;
  2. using Autodesk.AutoCAD.DatabaseServices;
  3. using Autodesk.AutoCAD.EditorInput;
  4. using Autodesk.AutoCAD.Geometry;
  5. using Autodesk.AutoCAD.Runtime;
  6. namespace tooltip
  7. {
  8.     public class Class1
  9.     {
  10.         Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  11.         [CommandMethod("TestOn")]
  12.         public void MyTestOn()
  13.         {
  14.             ed.PointMonitor += new PointMonitorEventHandler(ed_PointMonitor);
  15.         }
  16.         [CommandMethod("TestOff")]
  17.         public void MyTestOff()
  18.         {
  19.             ed.PointMonitor -= new PointMonitorEventHandler(ed_PointMonitor);
  20.         }
  21.         void ed_PointMonitor(object sender, PointMonitorEventArgs e)
  22.         {
  23.             Database db = HostApplicationServices.WorkingDatabase;
  24.             InputPointContext ipc = e.Context;
  25.             FullSubentityPath[] ePaths = ipc.GetPickedEntities();
  26.             if (ePaths.Length > 0)
  27.             {
  28.                 FullSubentityPath ePath = ePaths[0];
  29.                 using (Transaction trans = db.TransactionManager.StartTransaction())
  30.                 {
  31.                     ObjectId entId = ePath.GetObjectIds()[0];
  32.                     Entity ent = (Entity)trans.GetObject(entId, OpenMode.ForRead);
  33.                     e.AppendToolTipText("\n这是 :" + ent.GetType().FullName);
  34.                     trans.Commit();
  35.                 }
  36.             }
  37.         }
  38.     }
  39. }
加载DLL,输入teston命令后,用鼠标指向一个图元,会出现tooltip提示。用testoff命令可关掉这个功能。当然,你可以进一步修改代码,如显示扩展数据,加载DLL后功能即打开……

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2019-5-16 16:00 | 显示全部楼层
e.AppendToolTipText 不显示内容
发表于 2009-6-4 19:45 | 显示全部楼层

以前试过ToolTip,但有个问题,2010里的ToolTip是灰色的底色,

而代码实现的是蓝色的,有办法解决么?

发表于 2009-7-25 22:37 | 显示全部楼层

VB代码:

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.GeomeTry
Imports Autodesk.AutoCAD.Runtime

Namespace tooltip
    Public Class Class1
        Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor        <CommandMethod("TestOn")> _
        Public Sub MyTestOn()
                  AddHandler ed.PointMonitor, New PointMonitorEventHandler(AddressOf ed_PointMonitor)
        End Sub
        <CommandMethod("TestOff")> _
        Public Sub MyTestOff()
            RemoveHandler ed.PointMonitor, New PointMonitorEventHandler(AddressOf ed_PointMonitor)
        End Sub

        Private Sub ed_PointMonitor(ByVal sender As Object, ByVal e As PointMonitorEventArgs)
            Dim db As Database = HostApplicationServices.WorkingDatabase
            Dim ipc As InputPointContext = e.Context
            Dim ePaths() As FullSubentityPath = ipc.GetPickedEntities()
            If ePaths.Length > 0 Then
                Dim ePath As FullSubentityPath = ePaths(0)
                Dim trans As Transaction = db.TransactionManager.StartTransaction()
                Dim entId As ObjectId = ePath.GetObjectIds()(0)
                Dim ent As Entity = CType(trans.GetObject(entId, OpenMode.ForRead), Entity)
                e.AppendToolTipText(vbCrLf & "这是 :" + ent.GetType().FullName)
                trans.Commit()
            End If
        End Sub
    End Class
End Namespace

发表于 2009-7-28 11:42 | 显示全部楼层
学习学习
发表于 2009-8-11 19:09 | 显示全部楼层
没看懂,希望高手指点一下VBA部分的!
发表于 2011-1-14 20:01 | 显示全部楼层
我测试了一下,程序运行正常
可就是看不到ToolTip,不知是什么原因?
发表于 2011-5-3 10:12 | 显示全部楼层
好好学习,正是我要学习的东西
发表于 2013-11-6 10:43 | 显示全部楼层
我直接使用这个e.AppendToolTipText显示内容,为什么不显示呢?各位大神帮忙啊。。。谢谢了
发表于 2013-11-12 22:40 | 显示全部楼层
真不错的工具
发表于 2015-8-8 17:25 | 显示全部楼层
学习    了  赞   ~
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-3-29 18:41 , Processed in 0.223466 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表