Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
Numeric Edit Control - dot net version
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.vb.


bob
Does Msoft include a numeric edit control that allows you
to enter only numeric values similar to Creseant's? Dot
Net doesn't have a masked edit box so you'd have to use
the Active X control but it doesn't work as well as the
Creseants.

Thanks!!

Reply to this message...
Vote that this is a GOOD answer...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
Steve
Here's custom control code I adapted from "Professional VB.NET 2nd Edition"
by Wrox Press. I added properties to set number as positive-only or
integer-only. Create a custom control and build.

Imports System.ComponentModel

' Add your own path to the icon you want on the DLL

<ToolboxBitmap("C:\Documents and Settings\...\Numeric Only TextBox
Development\TextBox.ico")> _

Public Class TextBoxNumeric

Inherits System.Windows.Forms.TextBox

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'UserControl1 overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

components = New System.ComponentModel.Container()

End Sub

#End Region

Dim m_IntegerOnly As Boolean

Dim m_PositiveOnly As Boolean

<Description("If TRUE, only integers can be entered."), _

Browsable(True), _

Category("Validation"), _

DefaultValue(False)> _

Property IntegerOnly() As Boolean

Get

Return m_IntegerOnly

End Get

Set(ByVal Value As Boolean)

m_IntegerOnly = Value

End Set

End Property

<Description("If TRUE, only positive numbers can be entered."), _

Browsable(True), _

Category("Validation"), _

DefaultValue(False)> _

Property PositiveOnly() As Boolean

Get

Return m_PositiveOnly

End Get

Set(ByVal Value As Boolean)

m_PositiveOnly = Value

End Set

End Property

Private Sub NumericTextBox_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress

Dim KeyAscii As Integer

KeyAscii = Asc(e.KeyChar) ' NOTE: used as a flag when = 0 to mark bad values

Select Case KeyAscii

Case 48 To 57, 8, 13 ' Digits 0 - 9, Backspace, CR.

' These are OK, so accept them.

Case 45 ' Minus sign.

If PositiveOnly Then

KeyAscii = 0

Else

' Number can have only one minus sign, so if

' we already have one, throw this one away.

If InStr(Me.Text, "-") <> 0 Then

KeyAscii = 0

End If

' If the insertion point is not sitting at zero

' (i.e., the beginning of the field), throw away

' the minus sign because it's not valid anywhere

' but the first position

If Me.SelectionStart <> 0 Then

KeyAscii = 0

End If

End If

Case 46 ' Period (decimal point).

If IntegerOnly Then

KeyAscii = 0

Else

' If we already have one period, throw it away

If InStr(Me.Text, ".") <> 0 Then

KeyAscii = 0

End If

End If

Case Else ' Provide no handling for other keys.

KeyAscii = 0

End Select

' If we want to throw the keystroke away, then set the event

' as already handled. Otherwise, let the keystroke be

' handled normally.

If KeyAscii = 0 Then

e.Handled = True

Else

e.Handled = False

End If

End Sub

End Class

"bob" <Click here to reveal e-mail address> wrote in message
news:268101c2445e$6f591980$Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
Outlook interop - stopping user properties appearing on Outlook message print
Seriously, why is “cut and paste” majorly newsworthy???
 
    
bob
Thanks a bunch!!

[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
 
System.ComponentModel.Container
System.ComponentModel.IContainer
System.Web.UI.MobileControls.TextBox
System.Web.UI.WebControls.TextBox
System.Windows.Forms.KeyPressEventArgs
System.Windows.Forms.TextBox




Ad
BootFX
Reliable and powerful .NET application framework.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734