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

    [VB.NET] handles di tutte le textBox ...

    Ciao come posso attivare un ascoltatore (handles) per tutti i controlli textBox della mia classe?
    Pensavo a :

    codice:
    Private Sub myGotFocus() handles System.Windows.forms.form.controls.textBox
    
    end Sub
    ma non é valido ...

  2. #2
    trovato ...
    addHandler

    codice:
    Sub SetupEventHandlers()
        Dim ctrl As Control
        For Each ctrl In Me.Controls
            If TypeOf ctrl Is TextBox Then
                AddHandler ctrl.GotFocus, AddressOf Controls_GotFocus
                AddHandler ctrl.LostFocus, AddressOf Controls_LostFocus
            End If
        Next
    End Sub
    
    Private Sub Controls_GotFocus(ByVal sender As Object, _
        ByVal e As System.EventArgs) 
        Dim ctrl As Control = CType(sender, Control)
        ' In a real application you should use system-defined colors.
        ctrl.BackColor = Color.Yellow
    End Sub
    
    Private Sub Controls_LostFocus(ByVal sender As Object, _
        ByVal e As System.EventArgs) 
        Dim ctrl As Control = CType(sender, Control)
        ' In a real application you should use system-defined colors.
        ctrl.BackColor = Color.White
    End Sub

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.