[Gambas-user] NoTabFocus glitch when pressing shift (usercontrols)

Bruce adamnt42 at gmail.com
Tue Mar 9 00:42:28 CET 2021


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


More information about the User mailing list