C# WindowsForms NumericUpDown“不能等于 x 值”财产?
由于我的应用程序是二次根求解器,并且以 0
形式从 NumericUpDown 接收输入将引发 除以零
错误,我想知道这是否可能能够指定特定的 NumericUpDown 控件,根本无法设置为 0
。或者,用条件捕获并解决它是否更容易?
Due to my application being a quadratic root solver, and receiving input from a NumericUpDown in the form of 0
will throw a divide by zero
error, I was wondering if it was possible to be able to specify that particular NumericUpDown control, not able to be set to 0
at all. Or, is it just easier to catch that with a conditional and resolve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在验证事件中创建检查
,但您还需要在代码中进行检查,始终验证输入...
You can create a check in the Validating-event
But you also need the check in your code, always validate input...
NumericUpDown 有两个名为 Minimum 的属性和最大值,设置向上/向下控件的最小值和最大值。
您可以将其最小值设置为 1,这样用户将无法选择 0。
NumericUpDown has two properties calld Minimum and Maximum which set the min and max value for your up/down control.
You can just set its Minimum to 1 so the user won't be able to select 0.