netcai 发表于 2017-9-25 22:07:12

无法通过我的自定义面板创建图层?

我用一个按钮创建了一个面板,当我单击该按钮时,它将调用一个命令来创建图层和线型,但autocad总是提示我一个“eLockViolation”错误。
如果我不使用panel,代码将正确创建图层和线型。
public class Command
    {
      static PaletteSet palette;
      static bool wasVisible;
      ///
      /// Creates the palette if it did not already exist, and shwos it.
      ///
      
      public static void CreateGridPanel()
      {
            if (palette == null)
            {
                palette = new PaletteSet("CaiGrid", "CONVPALETTE", new Guid("{929CAC46-8606-4580-A953-238B70CA76A1}"));
                palette.Style =
                  PaletteSetStyles.ShowAutoHideButton |
                  PaletteSetStyles.ShowCloseButton |
                  PaletteSetStyles.ShowPropertiesMenu;
                palette.MinimumSize = new System.Drawing.Size(410, 240);
                palette.AddVisual("CaiGrid", new GridView());
                // Automatically hides the palette while there is no active document.
                var docs = Application.DocumentManager;
                docs.DocumentBecameCurrent += (s, e) => palette.Visible = e.Document == null ? false : wasVisible;
                docs.DocumentCreated += (s, e) => palette.Visible = wasVisible;
                docs.DocumentToBeDeactivated += (s, e) => wasVisible = palette.Visible;
                docs.DocumentToBeDestroyed += (s, e) =>
                {
                  wasVisible = palette.Visible;
                  if (docs.Count == 1)
                        palette.Visible = false;
                };
            }
            palette.Visible = true;
      }
}
**** Hidden Message *****

kdub 发表于 2017-9-25 22:47:04


调查
文档。LockDocument()<br>和google<strong>ElockDocument</strong><br>https://www.google.com.au/search?q=elockviolation+AutoCad

netcai 发表于 2017-9-25 22:56:21

谢谢kdub,现在工作了。
我想知道是否所有的非模态winform或panel都需要锁定文档?

gile 发表于 2017-9-26 01:25:06

你好,
来自Kean Walmsley的博客:

nobody 发表于 2017-9-27 02:37:23


如何“手动”锁定文档?

gile 发表于 2017-9-27 02:50:35

文档文档=Application.DocumentManager.MdiActiveDocument;。
如果(doc!=null)。
{。
使用(doc.LockDocument())。
{。
//您可以在这里安全地使用doc。
}。
}。
页: [1]
查看完整版本: 无法通过我的自定义面板创建图层?