cara buat numeric textbox

Bismillah.
kali ini saya akan share bagaimana caranya membuat numeric textbox di vb.net.
mis. ketika kita input angka 1000 di textbox maka putput yang akan dihasilkan atau yang muncul do textbox yaitu angka 1.000,, jika 10000 hasilnya 10.000 begitu seterusnya.
Adapun yang kita butuhkan adalah :
1.sebuah Form,
2.satu textbox
dan berikut ini syntaxnya :
_______________________________________________________________________

Public Class Form1
    Dim i As Long

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

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Try
            i = CInt(TextBox1.Text)
            TextBox1.Text = Format(i, "N0")
            TextBox1.Select(TextBox1.Text.Length, 0)
        Catch ex As Exception
            TextBox1.Text = "0"
        End Try
    End Sub
End Class
_______________________________________________________________________
Have a nice code.
:)
cara buat numeric textbox cara buat numeric textbox Reviewed by Syawaluddin Amin, S.Kom on Mei 09, 2013 Rating: 5

Tidak ada komentar:

Diberdayakan oleh Blogger.