Wednesday, October 11, 2017

ตัวอย่างการใช้ Decimal.TryParse, Validating

Private Sub TextBox1_Validating(ByVal sender As System.Object, _
            ByVal e As System.ComponentModel.CancelEventArgs) _
            Handles TextBox1.Validating
    Dim est As Decimal
    If TextBox1.Text.Length = 0 then Exit Sub   '' optional
    If Not Decimal.TryParse(TextBox1.Text.Trim, est) Then
        e.Cancel = True
        TextBox1.SelectAll()
    Else
        TextBox1.Text = est.ToString("N0")
    End If
End Sub

No comments:

Post a Comment