Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / March 2008

Tip: Looking for answers? Try searching our database.

Numeric textbox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Arne Garvander - 28 Feb 2008 17:35 GMT
How can a write a filter for a textbox that only accepts numeric input?
I tried the maskedTextBox, but i did not like it.

Signature

Arne Garvander
Certified Geek
Professional Data Dude

Alex Meleta - 28 Feb 2008 21:13 GMT
Hi Arne,

Like as answer: http://www.telerik.com/support/kb/article/b454K-hce-b454T-a-b454c-cbetemdget.aspx
Or simply check you test box changes for digitals: http://www.dotnetspider.com/code/C-550-Numeric-Text-Box-Accept-only-numbers.aspx 
(the OnKeyPress method is enough for instance)

Regards, Alex
[TechBlog] http://devkids.blogspot.com

> textbox
Claes Bergefall - 29 Feb 2008 09:47 GMT
Try this:

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 Win32.Native.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
       '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

> How can a write a filter for a textbox that only accepts numeric input?
> I tried the maskedTextBox, but i did not like it.
Arne Garvander - 29 Feb 2008 15:10 GMT
Are you missing an import statement? Win32.native does not compile.
Signature

Arne Garvander
Certified Geek
Professional Data Dude

> Try this:
>
[quoted text clipped - 45 lines]
> > How can a write a filter for a textbox that only accepts numeric input?
> > I tried the maskedTextBox, but i did not like it.
Claes Bergefall - 03 Mar 2008 10:01 GMT
Sorry about that, just remove it (ES_NUMBER is defined in the same class
anyway)

  /claes

> Are you missing an import statement? Win32.native does not compile.
>
[quoted text clipped - 48 lines]
>> > How can a write a filter for a textbox that only accepts numeric input?
>> > I tried the maskedTextBox, but i did not like it.
Mr. Arnold - 01 Mar 2008 23:10 GMT
> How can a write a filter for a textbox that only accepts numeric input?
> I tried the maskedTextBox, but i did not like it.

http://msdn2.microsoft.com/en-us/library/ms229644(VS.80).aspx

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.