none
Track Control Focus change RRS feed

  • Question

  • Hi,

    in a form i have 100s of controls (textboxes, buttons, checkboxes and list boxes). All i want is  - to track the control's focus change in a single function or event in the form.  Any idea?

    Regards

    Friday, December 21, 2012 5:13 AM

Answers

  • You can add control Enter event handler of all controls to single address like as 

     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            For Each ctrl As Control In Me.Controls
                AddHandler ctrl.Enter, AddressOf FocusChanged
            Next
    End Sub
    
     Private Sub FocusChanged(ByVal sender As Object, ByVal e As EventArgs)
    
        End Sub

    thanks


    Hirendra Sisodiya from authorcode.com

    • Marked as answer by ackid32 Saturday, December 22, 2012 4:20 AM
    Friday, December 21, 2012 6:14 AM

All replies

  • You can add control Enter event handler of all controls to single address like as 

     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            For Each ctrl As Control In Me.Controls
                AddHandler ctrl.Enter, AddressOf FocusChanged
            Next
    End Sub
    
     Private Sub FocusChanged(ByVal sender As Object, ByVal e As EventArgs)
    
        End Sub

    thanks


    Hirendra Sisodiya from authorcode.com

    • Marked as answer by ackid32 Saturday, December 22, 2012 4:20 AM
    Friday, December 21, 2012 6:14 AM
  • Yes, It works, this is what i want.

    Thanks

    Saturday, December 22, 2012 4:21 AM