Page 1 of 1

Moving a gadget like in the designer?

Posted: Mon Sep 19, 2005 10:14 pm
by TerryHough
See the image cut directly from the designer.

Image

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

Posted: Mon Sep 19, 2005 11:06 pm
by GreenGiant
I don't know if it's any use, but I think if you look *here* there is some visual designer code you can download.

Posted: Mon Sep 19, 2005 11:33 pm
by dagcrack
Since you said arrow keys and didnt mention the mouse, here I can show you how to do it with the arrow keys:

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
Hope that helps...

Posted: Mon Sep 19, 2005 11:36 pm
by srod
I know you specified using the keyboard, but you might find the following of interest nonetheless.

It uses the WIN API to easily move any gadget with the mouse.
I found it works best if you embed the gadget within a container gadget.

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

Posted: Tue Sep 20, 2005 4:12 pm
by TerryHough
Thanks for the replies.
dagcrack wrote: I can show you how to do it with the arrow keys
That is a big help. And I can use it

But, what causes the "handles" of the gadget display above to appear?
Is that some style setting?

Posted: Tue Sep 20, 2005 4:59 pm
by blueznl
perhaps drawn directly on the window?

a trick i used in the past was make a screen grab of that section and move that, not very elegant but worked well :-)

Posted: Tue Sep 20, 2005 8:43 pm
by dagcrack
ehm you can either screengrab the button or gadget, whatever you want to move. and draw the handles over that image... then move the image (and the gadget is hidden while you move, once you stopped moving, place the gadget at the new co-ords, unhide the gadget and get rid of the image).. perhaps? :)

Else you could always draw the handles at the side of the real gadget...