|
-
Feb 17th, 2007, 04:36 AM
#1
[2005] NumericTextbox
Dear All,
I am trying to develope a Numeric text control box as follows.But this not working properly.Can somebody help.
VB Code:
Public Class NumericTextboxControl
Inherits System.Windows.Forms.TextBox
Private _Handled As Boolean = False
Protected Overrides Function IsInputkey(ByVal Keychar As System.Windows.Forms.Keys) As Boolean
Select Case Keychar
Case Keys.NumPad0 To Keys.NumPad9 'Allow Numberpad 0-9
Return _Handled = True
Case Keys.Back 'Allow Backspace key
Return _Handled = True
Case Keys.D0 To Keys.D9 'Allow Decimal 0-9
Return _Handled = True
Case Else
Return _Handled = False
End Select
End Function
Public Property Handled() As Boolean
Get
Return _Handled
End Get
Set(ByVal value As Boolean)
_Handled = False
End Set
End Property
End Class
Last edited by danasegarane; Feb 17th, 2007 at 07:57 AM.
Please mark you thread resolved using the Thread Tools as shown
-
Feb 17th, 2007, 07:06 AM
#2
Hyperactive Member
Re: [2005] NumericTextbox
Give us a bit of a clue....... what's it not doing? what results are you getting?
If my post helps , please feel free to rate it 
-
Feb 17th, 2007, 07:37 AM
#3
Re: [2005] NumericTextbox
It allows both numeric and alphabets.I want to restrict to only Numbers.
Please mark you thread resolved using the Thread Tools as shown
-
Feb 17th, 2007, 11:05 AM
#4
Hyperactive Member
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
If my post helps , please feel free to rate it 
-
Feb 17th, 2007, 11:12 AM
#5
Hyperactive Member
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
If my post helps , please feel free to rate it 
-
Feb 18th, 2007, 11:15 PM
#6
Re: [2005] NumericTextbox
Dear Tinbeard,
Where do I place this codings.Can you please brief?
Please mark you thread resolved using the Thread Tools as shown
-
Feb 19th, 2007, 04:10 AM
#7
Hyperactive Member
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.
If my post helps , please feel free to rate it 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|