int num = 10; // 初始化默认值
PromptIntegerOptions intOpts = new PromptIntegerOptions("\n请输入一个整数(隔多少毫米一个点) [默认值: 10]: ")
{
DefaultValue = num, // 设置默认值
AllowNone = false, // 允许用户直接按回车使用默认值
LowerLimit = 1 // 可根据需求设置下限,避免无效输入(如0或负数)
};
PromptIntegerResult intResult;
do
{
intResult = ed.GetInteger(intOpts);
// 处理用户输入情况
if (intResult.Status == PromptStatus.Cancel )return;
else if (intResult.Status == PromptStatus.OK)
{
// 输入有效整数,获取输入值
num = intResult.Value;
break;
}
else
{
// 输入无效(非整数),提示重新输入
ed.WriteMessage("\n输入无效,请输入一个有效的整数!");
}
} while (true); // 循环直到获取有效输入或用户取消
12-05
7237
7237

被折叠的 条评论
为什么被折叠?



