ActiveControl?

InertiaM

Well-known member
Joined
Nov 3, 2007
Messages
663
Location
Kent, UK
Programming Experience
10+
VB.NET:
  If (TypeOf Me.ActiveControl Is TextBox) then
     ....
  End if

Compact Framework doesnt have an ActiveControl property. Any ideas :confused:
 
I think I've solved it (with some help from Google ;) )

VB.NET:
    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(ByVal 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 temp IsNot Nothing Then
                Return temp
            End If
        Next
        Return Nothing
    End Function
 
Back
Top