How to use Tab to go to next Gadget?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Nexus100
User
User
Posts: 55
Joined: Tue Feb 16, 2010 9:40 pm
Location: Essex, UK

How to use Tab to go to next Gadget?

Post by Nexus100 »

Hi Digital Maniacs

firstly as usual many thanks in advance!

Can anyone help me with this: I want the following;
If user types info into a text gadget and then presses TAB I want focus to change to the next gadget.

This seems to work from text gadget to text gadget, but on the last text gadget the next gadget is a button and focus either does not go to it (gadgets are created in the correct order) Or I need to have some help with code that allows the button to show it has focus and allows the user to either click with mouse OR press <RETURN>.

Thanks again!
All watched over by MACHINES..I am little more than #DigitalPlankton
Mr.L
Enthusiast
Enthusiast
Posts: 146
Joined: Sun Oct 09, 2011 7:39 am

Re: How to use Tab to go to next Gadget?

Post by Mr.L »

Hello!
I don't know if this is the most efficient solution but i once did it like that:

Code: Select all

OpenWindow(0,0,0,400,140,"Tab-Test")
StringGadget(0,10,10,380,20,"String1")
StringGadget(1,10,40,380,20,"String2")
StringGadget(2,10,70,380,20,"String3")
ButtonGadget(3,10,100,180,30,"Button1")
ButtonGadget(4,210,100,180,30,"Button2")

AddKeyboardShortcut(0,#PB_Shortcut_Tab,0)

Repeat
	Select WaitWindowEvent(50)
		Case #PB_Event_CloseWindow
			End
		Case #PB_Event_Menu			
			Select GetActiveGadget()
				Case 0	: SetActiveGadget(1)
				Case 1	: SetActiveGadget(2)
				Case 2	: SetActiveGadget(0)
				Case 3	: SetActiveGadget(4)
				Case 4	: SetActiveGadget(3)
			EndSelect
	EndSelect
ForEver
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: How to use Tab to go to next Gadget?

Post by ts-soft »

Works without shortcuts :wink:

Code: Select all

OpenWindow(0,0,0,400,140,"Tab-Test")
StringGadget(0,10,10,380,20,"String1")
StringGadget(1,10,40,380,20,"String2")
StringGadget(2,10,70,380,20,"String3")
ButtonGadget(3,10,100,180,30,"Button1")
ButtonGadget(4,210,100,180,30,"Button2")

SetActiveGadget(0)

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  SendMessage_(WindowID(0), #WM_CHANGEUISTATE, 2 | (1 << 16), 0)
CompilerEndIf

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      End
  EndSelect
ForEver
greetings - Thomas
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
buddymatkona
Enthusiast
Enthusiast
Posts: 252
Joined: Mon Aug 16, 2010 4:29 am

Re: How to use Tab to go to next Gadget?

Post by buddymatkona »

ts-soft has the right idea but I can not resist adding this. :)

Code: Select all

OpenWindow(0,0,0,400,140,"Tab-Test")
StringGadget(0,10,10,380,20,"String1")
StringGadget(1,10,40,380,20,"String2")
StringGadget(2,10,70,380,20,"String3")
ButtonGadget(3,10,100,180,30,"Button1", #PB_Button_Default )
ButtonGadget(4,210,100,180,30,"Button2", #ES_NOHIDESEL)
MaxGadget = 4
MinGadget = 0
TabCount = MinGadget - 1

AddKeyboardShortcut(0,#PB_Shortcut_Tab,0)

Repeat
   Select WaitWindowEvent(50)
      Case #PB_Event_CloseWindow
         End
       Case #PB_Event_Menu 
         TabCount = TabCount + 1
         If TabCount > MaxGadget
           Tabcount = MinGadget
         EndIf
         Select TabCount
           Case 0   : SetActiveGadget(0) 
           Case 1   : SetActiveGadget(1) 
            Case 2   : SetActiveGadget(2)
            Case 3   : SetActiveGadget(3)
              SendMessage_(WindowID(0), #WM_CHANGEUISTATE, 2 | (1 << 16), 0)
              For i = 1 To 3  
                SetGadgetText(3, "Click Me")
                Delay (900) 
                SetGadgetText(3, "Button1")
                Delay(700)
              Next i
            Case 4   : SetActiveGadget(4)
              SendMessage_(WindowID(0), #WM_CHANGEUISTATE, 2 | (1 << 16), 0)
                For i = 1 To 3  
                SetGadgetText(4, "No, Click Me! ")
                Delay (900) 
                SetGadgetText(4, "Button2")
                Delay(700)
              Next i     
         EndSelect
   EndSelect
ForEver
Mr.L
Enthusiast
Enthusiast
Posts: 146
Joined: Sun Oct 09, 2011 7:39 am

Re: How to use Tab to go to next Gadget?

Post by Mr.L »

Oh, I misunderstood the question :oops:
I thought he'd like to use the Tab-Key to cycle through the
Stringgadgets...
Post Reply