ActiveControl

  • Thread starter Thread starter Robert J
  • Start date Start date
Thanks Daniel

Here is the VB.Net flavour of the code for anyone that is interested.

Public Overridable Property ActiveControl() As Control
Get
Return GetFocusedControl(Me)
End Get
Set(ByVal Value As Control)
If (Not (Value.Focused)) Then
Value.Focus()
End If
End Set
End Property


Private Function GetFocusedControl(ByRef parent As Control) As Control
If (parent.Focused) Then
Return parent
End If
For Each ctrl As Control In parent.Controls
Dim temp As Control = GetFocusedControl(ctrl)
If (Not (temp Is Nothing)) Then
Return temp
End If
Next
Return Nothing
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top