i thought .net had a property to do this but i can't find it. what is the .net way to do it?
Printable View
i thought .net had a property to do this but i can't find it. what is the .net way to do it?
with keypress event
that allows decimals and negative numbers alsoCode:Private Sub OnKeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
e.Handled = (Not Char.IsControl(e.KeyChar)) AndAlso _
(Not Char.IsNumber(e.KeyChar)) AndAlso _
(Not (Char.IsPunctuation(e.KeyChar) And _
(((e.KeyChar = ".") And
(Text.IndexOf(".") = -1)) Or _
((e.KeyChar = "-") And (SelectionStart = 0)))))
End Sub
also take not that if it is something you may use more often, you can create a class that inherits TextBox and change Private to Protected Overrides for the event. Now you have a reusable numeric only textbox class that retains all the orginal textbox functionality
Isnt inheritance awesome?
.handled ok thanks bro