cad c# vs调试代码(按Esc继续执行代码,输入1则退出主程序)

效果如下:

cad c# vs调试代码(按Esc继续执行代码,输入1则退出主程序)_第1张图片

namespace IfoxDemo
{
    public static class 暂停调试
    {
        /// 
        /// 提示用户按Esc继续执行代码,输入1则退出主程序。
        /// 
        /// AutoCAD的编辑器对象。
        public static void 暂停()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            PromptDoubleOptions pdo = new PromptDoubleOptions("");
            pdo.AllowNegative = true; // 根据需要允许负数
            pdo.AllowZero = true; // 根据需要允许零
            try
            {
                double value =  ed.GetDouble(pdo).Value;
                if (value == 1)
                {
                    throw new InvalidOperationException("1抛出异常,退出程序");
                }
            }
            catch (System.Exception)
            {
                throw;
            }
          
        }
    }
}
 public static class Class1
 {
     [CommandMethod("xx")]
     public  static void Test()
     {
         for (int i = 0; i < 7; i++)
         {
             i.Print();
             暂停调试.暂停();
         }
     }
 }

你可能感兴趣的:(CAD,C#二次开发,c#,java,开发语言)