Visualizzazione dei risultati da 1 a 7 su 7
  1. #1
    paolo935
    Guest

    Inserimento di un texbox che accetti solo numeri : non mi funziona però

    ovrei in una form inserire un text box che accetti solo numeri ed escluda le lettere

    Ho provato a seguire un manuale di Microsoft.press (visual basic.net )

    Dice di inserire nell'evento keypress la seguente routine


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

    If Not (Char.IsDigit(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then
    e.Handled = True
    End If
    End Sub


    che non mi funziona : il textbox continua ad accettare tutti i tasti, ho provato ad inserire uno stop per vedere se ci passa e ho verificato che nnn sente neppure lo stop


    Private Sub quantita_ingrediente_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles quantita_ingrediente.KeyPress
    Stop
    If Not (Char.IsDigit(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then
    e.Handled = True
    End If
    End Sub

    qualcuno mi può dare una dritta ?

    grazie Paolo

  2. #2
    aggiungi questa riga nella sub New()
    AddHandler quantita_ingrediente.KeyPress, AddressOf ControllaTasto

    poi copia questa sub
    Private Sub ControllaTasto(ByVal o As [Object], ByVal e As KeyPressEventArgs)
    If e.KeyChar.IsNumber(e.KeyChar) Then
    e.Handled = False
    Else
    e.Handled = True
    End If
    End Sub

  3. #3
    paolo935
    Guest
    caspita funziona perfettamente, ho solo una piccola richiesta da farti

    è possibile abilitare anche il punto decimale del tastierino numerico?


    grazie ancora
    paolo

  4. #4
    paolo935
    Guest
    come non detto ci sono riuscito così

    grazie comunque paolo

    Private Sub ControllaTasto(ByVal o As [Object], ByVal e As KeyPressEventArgs)
    If e.KeyChar = "." Then Exit Sub
    If e.KeyChar.IsNumber(e.KeyChar) Then
    e.Handled = False
    Else
    e.Handled = True
    End If
    End Sub

  5. #5
    sostituisci la sub con questa:
    Private Sub ControllaTasto(ByVal o As [Object], ByVal e As KeyPressEventArgs)
    'controlla se il carattere digitato e' un carattere numerico
    'accetta anche "." e ","
    If e.KeyChar.IsNumber(e.KeyChar) _
    Or e.KeyChar = Microsoft.VisualBasic.ChrW(46) _
    Or e.KeyChar = Microsoft.VisualBasic.ChrW(44) Then
    e.Handled = False
    Else
    e.Handled = True
    End If
    End Sub

    :mavieni:

  6. #6
    paolo935
    Guest
    fantastico, grazie ancora

    paolo

  7. #7
    Foga27News
    Guest
    Però uno può fare copia/incolla...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.