Re: [2005] NumericTextbox
Give us a bit of a clue....... what's it not doing? what results are you getting?
Re: [2005] NumericTextbox
It allows both numeric and alphabets.I want to restrict to only Numbers.
Re: [2005] NumericTextbox
I'm assuming your creating a user control ?
This code will allow only numeric,backspace and periods, it also overrides the text property to allow it to be read in the host application.
The code needs modifying to stop multiple periods being entered.
VB Code:
'override the text property to allow it to be read in the
'host application
Public Overrides Property Text() As String
Get
Return NumericTextBox.Text
End Get
Set(ByVal Value As String)
End Set
End Property
Private Sub NumericTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles NumericTextBox.KeyPress
'basically this allows numbers,backspace and period
'need to modify to stop double periods being entered
e.Handled = Not Char.IsDigit(e.KeyChar) AndAlso Not Char.IsControl(e.KeyChar) AndAlso Not e.KeyChar = "."
End Sub
Re: [2005] NumericTextbox
This will stop multiple periods being entered....
VB Code:
Private Sub NumericTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles NumericTextBox.KeyPress
'basically this allows numbers,backspace and period
If e.KeyChar = "." AndAlso NumericTextBox.Text.IndexOf(".") > 0 Then
e.Handled = True
Else
e.Handled = Not Char.IsDigit(e.KeyChar) AndAlso Not Char.IsControl(e.KeyChar) AndAlso Not e.KeyChar = "."
End If
End Sub
Re: [2005] NumericTextbox
Dear Tinbeard,
Where do I place this codings.Can you please brief?
Re: [2005] NumericTextbox
Basically create a new user control, add a textbox to it then place the code within the class. I called my textbox 'NumericTextBox' but you can call it what you like, just modify the names in the code where applicable.