ssm
ssm

Reputation: 103

Textbox type fixing-Visual Basic.NET Framework 3.5

I am trying to develop a programe in Visual basic.ne(.NET Framework 3.5) where textbox will only accept integer. User wont be able to type char/decimel or other type.

Can anyone please help me?

Thanks in advance.

Upvotes: 1

Views: 372

Answers (3)

xpda
xpda

Reputation: 15813

I would consider using a NumericUpDown control instead of a TextBox. It does what you want and has arrows the user can click on to raise or lower the value.

Upvotes: 1

Wade73
Wade73

Reputation: 4509

Just handle the keypress event and test the keychar to make sure it is numeric.

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If Not IsNumeric(e.KeyChar) Then
            e.Handled = True
        End If
End Sub

Upvotes: 0

Jay Riggs
Jay Riggs

Reputation: 53603

Here's an article describing just the control you need (including not allowing decimals):

Simple Numeric TextBox

The article's code is C#, but as the author notes the control is packaged in a DLL you can use in a VB.NET project.

Upvotes: 0

Related Questions