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))