VB.net中的NumericUpDown验证 [英] NumericUpDown validation in VB.net

查看:180
本文介绍了VB.net中的NumericUpDown验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我在VB.net中验证NumericUpDown控件时遇到问题.我希望它仅接受数字,但也接受诸如''和单引号之类的标点符号,这是我在下面所做的代码,但问题仍然存在,我使用了keypress:

Hello, I have a problem in the validation of NumericUpDown control in VB.net. I want it to accept only the numbers, but it is accepting punctuations like ''.'' and apostrophe also, here my code what I did below, but still the problem persists, I used keypress:

推荐答案

如果不是那里的最好/如果/那么/其他结构,但是嘿.

无论如何,为什么不能仅将NumbericUpDown控件的DecimalPlaces属性设置为0?

然后,当您需要检索数据值时,可以使用Math.Floor函数将其转换为正确的int值(即未应用四舍五入(例如2.6仍转换为2))
Not the best if/then/else structure you got there, but hey.

Anyway, Why can you not just set the DecimalPlaces property of the NumbericUpDown control to 0?

Then when you need to retrieve the data value you can use Math.Floor function to convert to the correct int value (i.e. no rounding applied (e.g. 2.6 still converts to 2))


这篇关于VB.net中的NumericUpDown验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆