[Gambas-user] NoTabFocus glitch when pressing shift (usercontrols)
Bruce
adamnt42 at gmail.com
Tue Mar 9 08:58:20 CET 2021
On 9/3/21 10:12 am, Bruce wrote:
> On 9/3/21 7:22 am, Bruce Steers wrote:
>> This is weird.
>>
>> I I have a form full of custom usercontrols and have set NoTabFocus on
>> one.
>>
>> If i let the GUIs handle Tab focus then they get selected despite the
>> NoTabFocus flag.
>>
>> So i have written my own focus routine and grab the key events
>>
>> using up and down arrow and tab works fine and skips the NoTabFocus
>> object.
>>
>> Using Shift + Tab selects it :(
>>
>> Using Shift and Tab uses the exact same command as Up arrow but up arrow
>> works.
>> I am calling Stop Event to cancel Tab and Shift+Tab press anywhere else.
>>
>> Odd how Tab works but shift + Tab does not.
>>
>> Project is here...
>> https://gitlab.com/bsteers4/ncheckbox
>>
>> BruceS
>>
>>
>>
>> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>>
> Wade through the following and see if you can find something in it. It
> works here for all our custom controls.
>
> '' [EVT] Handler for the navigation keys
> Public Sub SELF_KeyPress()
>
> Dim hTarget As Control
>
> ' 1) Make [Enter] emulate a [Tab]
> If Key.Code = Key.Return Then
> ' a) figure out where to start looking
> If Key.Shift Then
> If Me.Previous Then
> hTarget = Me.Previous
> Else
> hTarget = Me.Parent.Children[Me.Parent.Children.Count - 1]
> Endif
> Else
> If Me.Next Then
> hTarget = Me.Next
> Else
> hTarget = Me.Parent.Children[0]
> Endif
> Endif
> ' b) find the next viable control
> While hTarget.NoTabFocus
> If Key.Shift Then
> hTarget = hTarget.Previous
> If Not hTarget Then hTarget =
> Me.Parent.Children[Me.Parent.Children.Count - 1]
> Else
> hTarget = hTarget.Next
> If Not hTarget Then hTarget = Me.Parent.Children[0]
> Debug hTarget.Name
> Endif
> Wend
> ' c) go there
> hTarget.SetFocus
>
> Endif
>
> rgrds
> bruce
Sorry - that was totally the wrong routine.
Look through tis one.
'' Resolves the previous "real" control to tab to (Possibly no longer
required)
Public Function PrevActiveControl(cControl As Control) As Control
Dim tControl As Control
Dim tContainer As Container
' Dim isContainer As Boolean
If IsNull(cControl.Previous) Then
' Print "No Prev for " & cControl.Name
If Not IsNull(cControl.Parent) Then
' Print "Has parent so try " & cControl.Parent.Name
Return PrevActiveControl(cControl.Parent)
Else
' Print "No parent (EOF?) so try " &
cControl.Window.Children[cControl.Window.Children.Count - 1].Name
tControl =
cControl.Window.Children[cControl.Window.Children.Count - 1]
Endif
Else
' Print "Got a target " & cControl.Previous.Name
tControl = cControl.Previous
Endif
While tControl Is Container
' Print "Target is a container, so try last child " &
tContainer.Children[tContainer.Children.Count - 1].Name
tContainer = tControl
If tContainer.Children.Count > 0 Then
tControl = tContainer.Children[tContainer.Children.Count - 1]
Else
Return PrevActiveControl(tControl)
Endif
Wend
If Not tControl.Enabled Then Return PrevActiveControl(tControl)
If Not tControl.Visible Then Return PrevActiveControl(tControl)
If tControl Is PictureBox Then Return PrevActiveControl(tControl)
If tControl Is Label Then Return PrevActiveControl(tControl)
' Print "Found next control " & tControl.Name
Return tControl
End
It is called from the control _KeyPress() handler as per the following
example.
If Key.Code = Key.Tab Then
Stop Event
InnerSpinBox_Activate
If Key.Shift Then
MUtil.PrevActiveControl(Me).SetFocus
Else
MUtil.NextActiveControl(Me).SetFocus
Endif
Endif
rdrds
bruce
More information about the User
mailing list