Public Class NumericTextBox
Inherits TextBox
Private Const ES_NUMBER As Integer = &H2000
Protected Overrides ReadOnly Property CreateParams() As
System.Windows. Forms.CreatePar ams
Get
Dim params As CreateParams = MyBase.CreatePa rams
params.Style = params.Style Or ES_NUMBER
Return params
End Get
End Property
Protected Overrides Function ProcessCmdKey(B yRef msg As
System.Windows. Forms.Message, ByVal keyData As System.Windows. Forms.Keys) As
Boolean
'Need to prevent pasting of non-numeric characters
If keyData = (Keys.Shift Or Keys.Insert) OrElse keyData =
(Keys.Control Or Keys.V) Then
Dim data As IDataObject = Clipboard.GetDa taObject
If data Is Nothing Then
Return MyBase.ProcessC mdKey(msg, keyData)
Else
Dim text As String =
CStr(data.GetDa ta(DataFormats. StringFormat, True))
If text = String.Empty Then
Return MyBase.ProcessC mdKey(msg, keyData)
Else
For Each ch As Char In text.ToCharArra y
If Not Char.IsNumber(c h) Then
Return True
End If
Next
Return MyBase.ProcessC mdKey(msg, keyData)
End If
End If
Else
Return MyBase.ProcessC mdKey(msg, keyData)
End If
End Function
End Class
/claes
"Reny" <re**@bxtech.co mwrote in message
news:ey******** ******@TK2MSFTN GP05.phx.gbl...
can any one tell how can i restrict my user to type just numeric character
in the textbox.I am using VS.NET 2003 (VB.NET)