开发者

TextBox max/min numeric value

I have a little problem - in my Windows Forms program I have a lot of text boxes. They only can get numeric values between 1 - 1024. "Protecting" the text box form non numeric inputs is no problem. But how can I assure that the value doesn't get higher than 1024? Is there any function or any event I could try to catch and then Handle it on my own? I thought about catching the "TextChanged" Event and then check for the value. But how can I know then which Button was the last one pressed? Besides I wouldn't like to exchange my Textboxes with any other Contr开发者_如何学Pythonols since they're all implemented right now and it would be a lot of work to exchange them all. Best Regards

Quendras


You should use the NumericUpDown control and set the Maximum property.


You could try using OnLostFocus on each text box. Then verify the input was numeric, and it's value is greater/equal to 0, and less/equal to 1024.


You could check when that textbox loses focus, and then check its value:

public sub Textbox1_lostFocus() handles textbox1.onLostFocus

    If cint(textbox1.text) > 1024 then
     'whatever you need to do here
    End if

end sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜