Is there a way to determine is any control at all on a form has gotten focus? I know you can individually determine if a single control has focus or has been clicked, etc. but is there an event that can tell you that some/any control has been clicked?

i.e.

Private Sub myFrm_Magic(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.SomethingClicked

  Msgbox(Me.ActiveControl.Name)

End Sub
Unhnd_Exception commented: I guess you figured it out on your own. -2
Member Avatar for Unhnd_Exception

Not without adding a handler to all of them.

Public Class Form1

    Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        ' Add a click event to all controls
        AddClickEventHandlers(Me)

    End Sub

    Private Sub AddClickEventHandlers(ByVal control As Control)
        'Recursivly add a handler to all controls
        AddHandler control.Click, AddressOf Control_Click

        For i = 0 To control.Controls.Count - 1
            AddClickEventHandlers(control.Controls(i))
        Next

    End Sub

    Private Sub RemoveClickEventHandlers(ByVal control As Control)

        RemoveHandler control.Click, AddressOf Control_Click

        For i = 0 To control.Controls.Count - 1
            RemoveClickEventHanglers(control.Controls(i))
        Next

    End Sub

    Private Sub Control_Click(ByVal sender As Object, ByVal e As EventArgs)
        MsgBox(CType(sender, Control).Name)
    End Sub

    Private Sub Form1_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
        RemoveClickEventHandlers(Me)
    End Sub

End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.