.NET(Mobile) フォームのActiveControlを探す

CompactFrameworkでフォームのActiveControlを探す方法です。
ComapactFrameworkではFormクラスのActiveControlプロパティがサポートされていません。


Public Class MyForm
    Inherits System.Windows.Forms.Form

    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
End Class

0 件のコメント: