Moving a gadget like in the designer?

Just starting out? Need help? Post your questions and find answers here.
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Moving a gadget like in the designer?

Post 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
GreenGiant
Enthusiast
Enthusiast
Posts: 252
Joined: Fri Feb 20, 2004 5:43 pm

Post 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.
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post 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...
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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
I may look like a mule, but I'm not a complete ass.
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post 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?
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post 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 :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post 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...
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
Post Reply