[Gambas-user] NoTabFocus glitch when pressing shift (usercontrols)
Bruce Steers
bsteers4 at gmail.com
Tue Mar 9 05:30:55 CET 2021
On Mon, 8 Mar 2021 at 23:43, Bruce <adamnt42 at gmail.com> 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
>
Awesome thanks bruce.
you know what? I did wade through it and thought,, hmm, although you are
doing things quite differently ii seems we are both still just getting the
prev/next control and then using SetFocus on it. :-\
So it had to be something else and i had to dig deeper, my initial thought
was I was not setting NoTabFocus properly..
But I eventually found my solution in the form of the following little
change...
from
* $hView.Focus = True*
to
* If Not Me.NoTabFocus Then $hView.Focus = True*
It seems the NoTabFocus property does actually set okay (as my own key
handler could see it)
But if the control has .Focus = True set the native tab handling routines
do not honour NoTabFocus.
And by the looks of my original issue the key handler event i set up worked
for everything except Shift+Tab for some reason that event was picked up by
something else (at a rough guess i'd say Form_KeyPress)
Thank you very much for the "tried and tested" code for me to compare.
BruceS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210309/24e4f1fc/attachment.htm>
More information about the User
mailing list