Re: how to impose numerical limits on a textbox??
- From: "cfps.Christian" <ge0193387@xxxxxxx>
- Date: Wed, 24 Oct 2007 15:55:51 -0000
On Oct 24, 10:19 am, we...@xxxxxxxxxx wrote:
Okay, that makes sense. However, I'm still new to VB. Can someone
please list some pseudocode to get me started?
Thanks,
-weg
I would create a class and have it inherit from textbox.
public class NumericTextBox
Inherits TextBox
Then I would define properties for the min and max value
public property MinValue as double
public property MaxValue as double
Grab a hold of the LostFocusEvent of the textbox to validate your box
public sub LostFocus ()
dim dbl as double
if Double.TryParse(me.text, dbl) then
if dbl > me.MaxValue then
me.Text = me.MaxValue.ToString()
throw exception
elseif dbl < me.MinValue then
me.Text = me.Minvalue.ToString()
throw exception
end if
else
'not a number
me.Text = me.MinValue.ToString() 'If you don't reset it you
could run into issues especially in textchanged
throw exception
end if
end sub
You can also do the above in the text changed event if you want to
validate it on every character not letting the user think they can
even input a number that big.
.
- References:
- how to impose numerical limits on a textbox??
- From: weg22
- Re: how to impose numerical limits on a textbox??
- From: Tom Shelton
- Re: how to impose numerical limits on a textbox??
- From: weg22
- how to impose numerical limits on a textbox??
- Prev by Date: Re: Overloads vs Shadows
- Next by Date: New File Creation
- Previous by thread: Re: how to impose numerical limits on a textbox??
- Next by thread: Problem drawing a WMF File VB.NET2005 (and Working in VB6)
- Index(es):
Relevant Pages
|