Gadget() Lost focus
Posted: Mon Dec 02, 2024 9:13 pm
This code block illustrates the situation in which the user removes focus from gadget(0) by placing the cursor in another getgad(), or uses Enter to advance to the next field.
In both situations it is necessary to ensure that the content of gadget(0) is correct.
When the content of gadget(0) is not correct, an informative message should be displayed.
Proposal:
1 Run the program.
2 Place the cursor in gadget(0).
3 Validate with Enter.
4 Analyze the result.
I assume that, as it is, it gives an inconvenient result.
Is it possible to validate the content of gadget(0), display a message to the user and continue execution normally?
Note: If the message is not displayed, there is no problem.
I appreciate all possible help.
In both situations it is necessary to ensure that the content of gadget(0) is correct.
When the content of gadget(0) is not correct, an informative message should be displayed.
Proposal:
1 Run the program.
2 Place the cursor in gadget(0).
3 Validate with Enter.
4 Analyze the result.
I assume that, as it is, it gives an inconvenient result.
Is it possible to validate the content of gadget(0), display a message to the user and continue execution normally?
Note: If the message is not displayed, there is no problem.
I appreciate all possible help.
Code: Select all
#ReturnKey=1
Procedure FocusLost(K)
Debug "gadget(0) LostFocus "+Str(K)
If GetGadgetText(0)="Input 0"
MessageRequester("","Wrong data")
SetActiveGadget(0)
Else
Debug "Correct data"
; MessageRequester("","Correct data")
SetActiveGadget(1)
EndIf
EndProcedure
Procedure FocusGet(N)
Debug "gadget(0) GetFocus "+Str(N)
EndProcedure
If OpenWindow(0, 0, 0, 430, 490, "Event handling example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StringGadget(0,10,10,100,25,"Input 0")
StringGadget(1,10,40,100,25,"Input 1")
StringGadget(2,10,80,100,25,"Input 2")
AddKeyboardShortcut(0, #PB_Shortcut_Return, #ReturnKey)
If CreateMenu(0, WindowID(0))
MenuTitle("Menu")
MenuItem(1, "Item 1")
MenuItem(2, "Item 2")
MenuItem(3, "Item 3")
EndIf
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case 0
Select EventType()
Case #PB_EventType_LostFocus
K+1
FocusLost(K)
Case #PB_EventType_Focus
N+1
FocusGet(N)
EndSelect
EndSelect
Case #PB_Event_Menu
Select EventMenu()
Case #ReturnKey
K+1
FocusLost(K)
Case 2 : Debug "Menu item 2 clicked!"
Case 3 : Debug "Menu item 3 clicked!"
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf