Move form by dragging imagegadget

Just starting out? Need help? Post your questions and find answers here.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Move form by dragging imagegadget

Post by Fangbeast »

I want to move a borderless form window by clicking on and holding down the mouse on a imagegadget.

Does anyone know how to do this? (I don't know what I am looking for.
Amateur Radio, D-STAR/VK3HAF
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Move form by dragging imagegadget

Post by Dude »

Based on someone else's code:

Code: Select all

If OpenWindow(1,150,150,300,100,"",#PB_Window_BorderLess)
  CreateImage(1,100,50,24,#Red)
  ImageGadget(1,10,10,100,50,ImageID(1))
  Repeat
    event=WaitWindowEvent()
    If GetAsyncKeyState_(#VK_LBUTTON)<>0
      GetCursorPos_(@cursor_pos.POINT)
      ScreenToClient_(WindowID(1),@cursor_pos)
      hChild=RealChildWindowFromPoint_(WindowID(1),PeekQ(cursor_pos))
      If hChild=GadgetID(1)
        ReleaseCapture_()
        SendMessage_(WindowID(1),#WM_NCLBUTTONDOWN,#HTCAPTION,0)
      EndIf
    EndIf
  Until event=#PB_Event_CloseWindow
EndIf
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Move form by dragging imagegadget

Post by RASHAD »

Hi Fang
Cross platform

Code: Select all

If OpenWindow(0, 0, 0, 400, 400, "Moving Borderless Window", #PB_Window_BorderLess | #PB_Window_ScreenCentered)
  SetWindowColor(0,$B9B9B9)
  CanvasGadget(0,10,10,380,40)
  CanvasGadget(1,10,350,40,40)
   
  StartDrawing(CanvasOutput(0))
    Box(0,0,OutputWidth(),OutputHeight(),$0F)
    Box(2,2,OutputWidth()-4,OutputHeight()-4,$B3FEA8)
  StopDrawing()
  
  StartDrawing(CanvasOutput(1))
    Box(0,0,OutputWidth(),OutputHeight(),$0F)
    Box(2,2,OutputWidth()-4,OutputHeight()-4,$111FFF)
    DrawingMode(#PB_2DDrawing_Transparent )
    DrawText(15,12,"X",$FFFFFF)
  StopDrawing()
   
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          Select EventType()
            Case #PB_EventType_LeftButtonDown
              If run = 0
                run = 1
                ox = WindowMouseX(0)
                oy = WindowMouseY(0)
              EndIf
              
            Case #PB_EventType_LeftButtonUp
              run = 0
              
            Case #PB_EventType_MouseMove
              If GetGadgetAttribute(0,#PB_Canvas_Buttons ) =  #PB_Canvas_LeftButton
                ResizeWindow(0,DesktopMouseX()-ox,DesktopMouseY()-oy,#PB_Ignore,#PB_Ignore)
              EndIf
          EndSelect
          
        Case 1
          Select EventType()
            Case #PB_EventType_LeftButtonDown
              End
          EndSelect            
      EndSelect
  EndSelect
ForEver
EndIf
Egypt my love
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Move form by dragging imagegadget

Post by Fangbeast »

Thanks Dude and RASHAD. I now have something to do before my minority intellect ossifies:):)
Amateur Radio, D-STAR/VK3HAF
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Move form by dragging imagegadget

Post by Fangbeast »

RASHAD wrote:Hi Fang
Cross platform

Code: Select all

If OpenWindow(0, 0, 0, 400, 400, "Moving Borderless Window", #PB_Window_BorderLess | #PB_Window_ScreenCentered)
  SetWindowColor(0,$B9B9B9)
  CanvasGadget(0,10,10,380,40)
  CanvasGadget(1,10,350,40,40)
   
  StartDrawing(CanvasOutput(0))
    Box(0,0,OutputWidth(),OutputHeight(),$0F)
    Box(2,2,OutputWidth()-4,OutputHeight()-4,$B3FEA8)
  StopDrawing()
  
  StartDrawing(CanvasOutput(1))
    Box(0,0,OutputWidth(),OutputHeight(),$0F)
    Box(2,2,OutputWidth()-4,OutputHeight()-4,$111FFF)
    DrawingMode(#PB_2DDrawing_Transparent )
    DrawText(15,12,"X",$FFFFFF)
  StopDrawing()
   
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          Select EventType()
            Case #PB_EventType_LeftButtonDown
              If run = 0
                run = 1
                ox = WindowMouseX(0)
                oy = WindowMouseY(0)
              EndIf
              
            Case #PB_EventType_LeftButtonUp
              run = 0
              
            Case #PB_EventType_MouseMove
              If GetGadgetAttribute(0,#PB_Canvas_Buttons ) =  #PB_Canvas_LeftButton
                ResizeWindow(0,DesktopMouseX()-ox,DesktopMouseY()-oy,#PB_Ignore,#PB_Ignore)
              EndIf
          EndSelect
          
        Case 1
          Select EventType()
            Case #PB_EventType_LeftButtonDown
              End
          EndSelect            
      EndSelect
  EndSelect
ForEver
EndIf
RASHAD, can this be done with an imagegadget instead? (No canvas involved)

I tried to add your code to my form and it didn't work predictably. I thought I did it right:)
Amateur Radio, D-STAR/VK3HAF
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Move form by dragging imagegadget

Post by Fangbeast »

Dude wrote:Based on someone else's code:

Code: Select all

If OpenWindow(1,150,150,300,100,"",#PB_Window_BorderLess)
  CreateImage(1,100,50,24,#Red)
  ImageGadget(1,10,10,100,50,ImageID(1))
  Repeat
    event=WaitWindowEvent()
    If GetAsyncKeyState_(#VK_LBUTTON)<>0
      GetCursorPos_(@cursor_pos.POINT)
      ScreenToClient_(WindowID(1),@cursor_pos)
      hChild=RealChildWindowFromPoint_(WindowID(1),PeekQ(cursor_pos))
      If hChild=GadgetID(1)
        ReleaseCapture_()
        SendMessage_(WindowID(1),#WM_NCLBUTTONDOWN,#HTCAPTION,0)
      EndIf
    EndIf
This one works with my code, thanks.

Until event=#PB_Event_CloseWindow
EndIf
[/code]
Amateur Radio, D-STAR/VK3HAF
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Move form by dragging imagegadget

Post by RASHAD »

As per your request

Code: Select all

LoadImage(0, #PB_Compiler_Home + "examples/Sources/Data/PureBasicLogo.bmp")

If OpenWindow(0, 0, 0, 400, 400, "Moving Borderless Window", #PB_Window_BorderLess | #PB_Window_ScreenCentered)
  SetWindowColor(0,$B9B9B9)
  ImageGadget(0,10,10,380,40,ImageID(0))
  DisableGadget(0,1)
  CreateImage(1,40,40,24,$0000FF)
  StartDrawing(ImageOutput(1))
    DrawingMode(#PB_2DDrawing_Transparent )
    DrawText(14,12,"X",$FFFFFF)
  StopDrawing()
  ImageGadget(1,10,350,40,40,ImageID(1))
Repeat
  Select WaitWindowEvent()
    Case #WM_LBUTTONDOWN
        If WindowMouseX(0) > 10 And WindowMouseX(0) < GadgetWidth(0) And WindowMouseY(0) > 10 And WindowMouseY(0) < (GadgetHeight(0)+10)
          SendMessage_(WindowID(0),#WM_NCLBUTTONDOWN,#HTCAPTION,0)
        EndIf
        
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 1
          End
      EndSelect
  EndSelect
ForEver
EndIf
Egypt my love
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Move form by dragging imagegadget

Post by Fangbeast »

Thank you master RASHAD. It was 35 degrees yesterday and my brains are currently mushy goo.
Amateur Radio, D-STAR/VK3HAF
Post Reply