Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    [vb.net] Intercettare il controllo per passarlo alla funzione

    Salve, ho diversi controlli che devo accettare solo numeri:

    -----
    Private Sub TextBox_SoloNumeri(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
    If Char.IsDigit(e.KeyChar) Or Char.IsControl(e.KeyChar) Then
    ElseIf e.KeyChar = "." And Me.TextBox1.Text.IndexOf(".") = -1 Then
    Else
    e.Handled = True
    End If
    End Sub
    -----

    Adesso come posso passare alla funzione il nome del controllo? (...Me.TextBox1.Text.IndexOf...)

  2. #2
    codice:
    Private Sub TextBox_SoloNumeri(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress, TextBox2.KeyPress, TextBox3.KeyPress 'eccetera
    If Char.IsDigit(e.KeyChar) Or Char.IsControl(e.KeyChar) Then
    ElseIf e.KeyChar = "." And DirectCast(sender, TextBox).Text.IndexOf(".") = -1 Then
    Else
    e.Handled = True
    End If
    End Sub
    Amaro C++, il gusto pieno dell'undefined behavior.

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.