Re: allowing just numeric value in my textbox

Tech-Archive recommends: Fix windows errors by optimizing your registry



Public Class NumericTextBox
Inherits TextBox

Private Const ES_NUMBER As Integer = &H2000

Protected Overrides ReadOnly Property CreateParams() As
System.Windows.Forms.CreateParams
Get
Dim params As CreateParams = MyBase.CreateParams
params.Style = params.Style Or ES_NUMBER
Return params
End Get
End Property

Protected Overrides Function ProcessCmdKey(ByRef 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.GetDataObject
If data Is Nothing Then
Return MyBase.ProcessCmdKey(msg, keyData)
Else
Dim text As String =
CStr(data.GetData(DataFormats.StringFormat, True))
If text = String.Empty Then
Return MyBase.ProcessCmdKey(msg, keyData)
Else
For Each ch As Char In text.ToCharArray
If Not Char.IsNumber(ch) Then
Return True
End If
Next
Return MyBase.ProcessCmdKey(msg, keyData)
End If
End If
Else
Return MyBase.ProcessCmdKey(msg, keyData)
End If
End Function
End Class

/claes

"Reny" <reny@xxxxxxxxxx> wrote in message
news:ey8Sdf7sGHA.2036@xxxxxxxxxxxxxxxxxxxxxxx
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)




.



Relevant Pages

  • Re: Numeric textbox
    ... Protected Overrides ReadOnly Property CreateParams() As ... Dim params As CreateParams = MyBase.CreateParams ... Dim data As IDataObject = Clipboard.GetDataObject ... Return MyBase.ProcessCmdKey(msg, keyData) ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: How to hide the numericUpDown controls up and down arrows?
    ... Protected Overrides ReadOnly Property CreateParams() As ... Dim params As CreateParams = MyBase.CreateParams ... Dim data As IDataObject = Clipboard.GetDataObject ... Return MyBase.ProcessCmdKey(msg, keyData) ...
    (microsoft.public.dotnet.framework.windowsforms)
  • RE: how to deploy stored procedures onsite
    ... You can give a VB Script file as below. ... Dim cmd ... Dim params ...
    (microsoft.public.dotnet.framework.aspnet)
  • OO4O and Spatial
    ... input object for field and parameters ... Dim oraSession As New OracleInProcServer.OraSessionClass ... Dim sql As String ... Dim params As OracleInProcServer.OraParameters ...
    (comp.databases.oracle.misc)