
In the designer, a field selected like this can be moved using the arrow
keys.
I need a similar capability in my program. How is this done?
Thanks,
Terry
Code: Select all
;move gadget with keyboard arrow keys example
; by dagcrack
hwnd = OpenWindow(#PB_Any,0,0,320,240,#PB_Window_ScreenCentered|#PB_Window_SystemMenu,"test")
CreateGadgetList(WindowID(hwnd))
cy = 10 : cx = 10 ; initial values...
button = StringGadget(#PB_Any,cx,cy,100,20,"move me with keys")
Repeat
event = WaitWindowEvent()
If event = #WM_KEYDOWN
If GetAsyncKeyState_(#VK_DOWN)
cy = cy + 5
EndIf
If GetAsyncKeyState_(#VK_UP)
cy = cy - 5
EndIf
If GetAsyncKeyState_(#VK_RIGHT)
cx = cx + 5
EndIf
If GetAsyncKeyState_(#VK_LEFT)
cx = cx - 5
EndIf
ResizeGadget(button , cx ,cy,-1,-1)
EndIf
Until event = #PB_Event_CloseWindow
End
Code: Select all
Procedure.l MouseOverGadget()
GetCursorPos_(@cursor_pos.POINT)
ScreenToClient_(WindowID(),@cursor_pos)
hChild = ChildWindowFromPoint_(WindowID(), cursor_pos\x,cursor_pos\y)
procedurereturn GetDlgCtrlID_(hChild)
EndProcedure
If OpenWindow(0,0,0,640,300,#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_Invisible|#PB_Window_ScreenCentered,"egrids test program.") And CreateGadgetList(WindowID(0))
ShowWindow_(WindowID(), #SW_MAXIMIZE)
containergadget(1,20,50,100,40,#PB_Container_Raised)
textgadget(10, 10,10,80, 15, "Click and drag")
closegadgetlist()
containergadget(2,20,100,100,40,#PB_Container_Raised)
textgadget(11, 10,10,80, 15, "Click and drag")
closegadgetlist()
containergadget(3,20,150,100,40,#PB_Container_Raised)
textgadget(12, 10,10,80, 15, "Click and drag")
closegadgetlist()
containergadget(4,20,200,100,40,#PB_Container_Raised)
textgadget(13, 10,10,80, 15, "Click and drag")
closegadgetlist()
containergadget(5,20,250,100,40,#PB_Container_Raised)
textgadget(14, 10,10,80, 15, "Click and drag")
closegadgetlist()
Repeat
EventID = WaitWindowEvent()
Select EventID
Case #WM_LBUTTONDOWN
gad = MouseOverGadget()
if gad > 0
ReleaseCapture_()
SendMessage_(gadgetid(gad), #WM_NCLBUTTONDOWN, #HTCAPTION, NULL)
endif
EndSelect
Until EventID = #PB_Event_CloseWindow
EndIf