我有一个Windows窗体,当鼠标右键从datagridview单元格点击时,程序会要求用户在autocad图形中选择一个图元,除了光标是Windows光标,而不是拾取框之外,一切都正常用户必须在图形中单击,然后更改cusor
我使用了SetFocus函数(
[DllImport(“user32.dll”)]
),但它不起作用。有人能告诉我如何自动显示拾取框图标吗
vs2019+AutoCAD2019
- [DllImport("user32.dll")]
- public static extern System.IntPtr SetFocus(System.IntPtr hwnd);
- private void EntityDataGridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
- {
- if (e.Button != MouseButtons.Right)
- return;
- int rowIdx = e.RowIndex;
- int colIdx = e.ColumnIndex;
- if (rowIdx == -1 || colIdx != 0)
- return;
-
- this.Hide();
- Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
- Database db = HostApplicationServices.WorkingDatabase;
- Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- //SetFocus doesn't work!
- SetFocus(doc.Window.Handle);
- PromptEntityOptions p = new PromptEntityOptions("\nPlease Select\n");
- PromptEntityResult res = ed.GetEntity(p);
- if (res.Status != PromptStatus.OK)
- return;
- ObjectId id = res.ObjectId;
- string layerName = string.Empty;
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- DBObject obj = tr.GetObject(id, OpenMode.ForRead);
- if (obj is Entity)
- {
- Entity ent = obj as Entity;
- layerName = ent.Layer;
- }
- tr.Commit();
- }
- this.Show();
- MessageBox.Show(layerName);
- }
本帖以下内容被隐藏保护;需要你回复后,才能看到! 游客,如果您要查看本帖隐藏内容请 回复 |