如何使用光标从用户获得坐标 [英] How to get a co ordinates from user using cursor

查看:115
本文介绍了如何使用光标从用户获得坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[CommandMethod("ha")]
       public static void FindAllHatches()
       {
           float x = 25, y = 15, z;
           Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
           Document acDoc = Application.DocumentManager.MdiActiveDocument;
 
           var db = acDoc.Database;
           using (Transaction transaction = db.TransactionManager.StartTransaction())
           {
               ObjectId idModelSpace = SymbolUtilityServices.GetBlockModelSpaceId(db);
 
               BlockTableRecord modelSpace = transaction.GetObject(idModelSpace, OpenMode.ForWrite) as
                   BlockTableRecord;
 
               foreach (var objId in modelSpace)
               {
                   MText mtext = new MText();
                   mtext.Width = 6;
                   mtext.Location = new Point3d(x, y, z = 0);
                   ////acpt = new Point3d(acpt.X, acpt.Y + 2, acpt.Z);

                   var entity = transaction.GetObject(objId, OpenMode.ForRead);
                   Hatch hatch = entity as Hatch;
                   if (hatch == null)
                       continue; //not hatch

                   mtext.Contents = ("\n" + "\n The area of hatch is: " + hatch.Area + hatch.PatternName + hatch.Color);
 
                   acDoc.Editor.WriteMessage("\n" + "\n The area of hatch is:" + hatch.Area + hatch.PatternName + hatch.Color);
 
                   modelSpace.AppendEntity(mtext);
                   transaction.AddNewlyCreatedDBObject(mtext, true);
                   y--;
               }
               transaction.Commit();
           }
       }





我的尝试:



上面代码的输出是图形中的阴影区域,我希望将输出显示给用户指定的点bt我希望通过光标获得的点或者鼠标或鼠标单击。



What I have tried:

The output of the above code is area of hatches in the drawing and i want to display the output to the user specified points bt that points i want to get by cursor i.e.entered by or mouse click.

推荐答案

MousePosition 属性,无论你正在绘制什么东西,都会告诉你鼠标指针在哪里。

承担请注意,即使您正在调用控件的方法,也会获得屏幕坐标。要打印某些内容,通常需要控制坐标。 Control.PointToClient 将翻译为你。
The MousePosition property of your Form, Panel, whatever you're drawing your stuff on will tell you where the mouse pointer is.
Bear in mind that you get screen co-ordinates, even though you're calling a control's method. To print something, you will typically need control co-ordinates. Control.PointToClient will translate for you.


这篇关于如何使用光标从用户获得坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆