Page 1 of 1
Spin gadget retains focus and is selected after value change
Posted: Tue Jun 14, 2016 8:45 pm
by barryem
With the spin gadget set to #PB_Spin_ReadOnly I would expect that when the number is changed using an arrow button the spin control wouldn't retain focus and show reverse text as being selected but it does. Is there a way to prevent that?
Here's the sample code from the help file with #PB_Spin_ReadOnly added, as an example:
Code: Select all
If OpenWindow(0, 0, 0, 140, 70, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SpinGadget (0, 20, 20, 100, 25, 0, 10, #PB_Spin_ReadOnly)
SetGadgetState (0, 5) : SetGadgetText(0, "5") ; set initial value
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
If EventGadget() = 0
SetGadgetText(0, Str(GetGadgetState(0)))
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
I'm doing this in Windows 10 using PB 5.42 in case that matters.
Any suggestions appreciated, up to and including "because we felt like doing it that way."
Barry
Re: Spin gadget retains focus and is selected after value ch
Posted: Tue Jun 14, 2016 10:15 pm
by RASHAD
Hi
# 1:
Code: Select all
If OpenWindow(0, 0, 0, 140, 70, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SpinGadget (0, 20, 20, 100, 25, 0, 10, #PB_Spin_ReadOnly)
Dummy = TextGadget(#PB_Any,0,0,0,0,"")
SetGadgetState (0, 5) : SetGadgetText(0, "5") ; set initial value
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
If EventGadget() = 0
SetGadgetText(0, Str(GetGadgetState(0)))
SetActiveGadget(Dummy)
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
# 2:
Code: Select all
If OpenWindow(0, 0, 0, 140, 70, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SpinGadget (0, 20, 20, 100, 25, 0, 10, #PB_Spin_ReadOnly)
SetGadgetState (0, 5) : SetGadgetText(0, "5") ; set initial value
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
If EventGadget() = 0
SetGadgetText(0, Str(GetGadgetState(0)))
SendMessage_(GadgetID(0),#WM_KILLFOCUS,0,0)
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
Re: Spin gadget retains focus and is selected after value ch
Posted: Tue Jun 14, 2016 10:40 pm
by barryem
Both examples do just what I hoped for. I think I'll use the second one because it seems a little cleaner.
Thanks,
Barry
Re: Spin gadget retains focus and is selected after value ch
Posted: Tue Jun 14, 2016 11:14 pm
by Demivec
@RASHAD: You don't have to create a dummy gadget in your example #1.
You can use SetActiveGadget(-1) instead.
Code: Select all
If OpenWindow(0, 0, 0, 140, 70, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SpinGadget (0, 20, 20, 100, 25, 0, 10, #PB_Spin_ReadOnly)
SetGadgetState (0, 5) : SetGadgetText(0, "5") ; set initial value
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
If EventGadget() = 0
SetGadgetText(0, Str(GetGadgetState(0)))
SetActiveGadget(-1)
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
Re: Spin gadget retains focus and is selected after value ch
Posted: Wed Jun 15, 2016 12:12 am
by RASHAD
Hi Demivec
I missed that one (it is since 5.4x only I think)
Thanks
Re: Spin gadget retains focus and is selected after value ch
Posted: Thu Jun 16, 2016 10:25 pm
by mestnyi
You can use SetActiveGadget(-1) instead.
Note: This is not roll in Linux
Re: Spin gadget retains focus and is selected after value ch
Posted: Sat Jun 18, 2016 10:39 pm
by Demivec
mestnyi wrote:You can use SetActiveGadget(-1) instead.
Note: This is not roll in Linux
What does it do in Linux?