1.
create
component that inherit textbox,
now create
property,
maxVal & minVal
then overrite
keypress event
and in key press event check, keychar is integer and it is < maxValue & > minVal
now build project, you will get this new control in toolbox
use it instead of normal texbox, set min & max value properties....
for runtime controlling max & min values, just take user input for both,
then...
MyTxtbox1.MaxVal= convert.toint32(txtInputMax.text)
MyTxtbox1.MinVal= convert.toint32(txtInputMin.text)
MyTxtbox2.MaxVal= convert.toint32(txtInputMax.text)
MyTxtbox2.MinVal= convert.toint32(txtInputMin.text)
it is component so, you can use it in various projects and, it is also number kind of textbox then it will not need to validate every time, it will reduce your code.
you can also make properties like, decimal places... etc
some links for code
NumericTextBox (C#.NET)[
^]
Numeric TextBox[
^]
Numeric TextBox : Allow your users to enter numeric data the easy way[
^]
http://stackoverflow.com/questions/9969824/vb-net-need-text-box-to-only-accept-numbers[
^]
2.
use
Numeic updown control / range validator
Textbox Max Min value[
^]
Happy Coding!
:)