Originariamente inviato da mardok30
Se, come immagino, nella textbox devi inserire dei numeri con la virgola il codice che hai scritto non va bene perché, per esempio, ti permette di inserire anche più di una virgola...
Io uso una classe del genere:
codice:
Public Class CKeyFilterPunto 
    Public Sub OnlyNumbersAndComma(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        Dim TB As TextBox
        TB = CType(sender, TextBox)

        Dim s As [String] = TB.Text.ToString()
        Dim DecimalSeparator1 As String = ","

        Dim Virgola As Integer = s.IndexOf(DecimalSeparator1.ToString(), 0, s.Length)
           If Virgola = -1 Then
            If Not (Char.IsDigit(e.KeyChar) Or Char.IsControl(e.KeyChar) Or DecimalSeparator1.IndexOf(e.KeyChar) <> -1) Then
                e.Handled = True
            End If
        Else
            If Not (Char.IsDigit(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then
                e.Handled = True
            End If
        End If
    End Sub
End Class
Crea questa variabile a livello di Form:
codice:
Private CkfVirgolaEPunto As New CKeyFilterPuntoEVirgola
e la assegno alla KeyPress della Textbox
codice:
AddHandler TextBox.KeyPress, AddressOf Ckf.OnlyNumbersAndComma

A me servirebbe una cosa così!
Solo che non ho capito l'ultimo passaggio dell'handle...

per caso è possibile far si che oltre i numeri e la virgola accetti anche il punto ma trasformandolo in virgola?

Non l'ho capita sta classe xD

per ora sto usando:
codice:
        If e.KeyChar = "." Then
            e.KeyChar = ","
        Else
            If Not (Char.IsDigit(e.KeyChar) Or e.KeyChar = ","c) Then
                e.Handled = True
                Beep()
            End If
        End If
che funziona benissimo se nn fosse che appunto non va il BackSpace xD