Code for Determining Selected control on a form in .net

following example show that how to find selected control on the windows form, or if we can determine active control(which control has focus) on the windows form , then we can use this code of sample.


    Private Sub GetActiveControl()
        Dim Ctrl As Control = Me.ActiveControl
        MessageBox.Show("Active control is " & Ctrl.Name)
    End Sub


private void GetActiveControl()
    Control Ctrl = this.ActiveControl;
    MessageBox.Show("Active control is " + Ctrl.Name);