Was running along the same line. and as Usual things are a bit more complicated then MSDN let's you believe
The problem I'm not able to solve is if a form has zero controls that can recieve focus, in that scenario the usercontrole still will accept focus.
Normally you could concider to ignore that, but a form showing data that's locked by another user is typically a form with all controls set to Enabled = False
Code:Private Sub TextboxPlus_Enter(sender As Object, e As EventArgs) Handles Me.Enter If Not _enabled Then SelectNext(Me) End If End Sub Private Function SelectNext(Ctrl As Control) As Boolean Dim container As Control Dim result As Boolean container = Ctrl.Parent If container IsNot Nothing AndAlso Ctrl.Parent.Controls.Count > 1 Then 'search on parent control For Each itm As Control In container.Controls If itm IsNot Ctrl Then 'don't bother to check already searched part of the tree If itm.CanFocus Then 'ther is another control the paren that can focus result = True container.SelectNextControl(Ctrl, True, True, True, True) Exit For ElseIf itm.Controls.Count > 0 Then 'this control hold ome other controls... to investigate If SelectNext(itm.Controls(0)) Then result = True Exit For End If End If End If Next End If If Not result AndAlso container.Parent IsNot Nothing Then result = SelectNext(container) End If Return result End Function




Reply With Quote
