[Gambas-user] How to move an object within a form

Werner wdahn at ...1000...
Mon Jan 18 13:42:34 CET 2010


On 18/01/10 19:27, Fiddler63 wrote:
> I'm trying to move an object within a form.
> The following code allows me to move the form, but not the object within the
> form, ie when I click on the mouse I can move the form around on the screen,
> but no the object within the form.
>
> Any suggestions ?
>
> PRIVATE $MX AS Integer
> PRIVATE $MY AS Integer
>
> PUBLIC SUB DrawingArea1_MouseDown()
>  $MX = Mouse.ScreenX - ME.X
>  $MY = Mouse.ScreenY - ME.Y
> END
>
> PUBLIC SUB DrawingArea1_MouseMove()
>   ME.Move(Mouse.ScreenX - $MX, Mouse.ScreenY - $MY) 
> END
>   
ME relates to the form, not the Drawing Area.



This works for me:
'----------------------------------------------
Private thePicture As New Picture


Public Sub Form_Open()
  thePicture = Picture.Load("/home/werda/Desktop/Wolf.jpg")
  DrawingArea1.Resize(thePicture.Width, thePicture.Height)
End

Public Sub DrawingArea1_Draw()
  Draw.Picture(thePicture, 0, 0)
End


Public Sub DrawingArea1_MouseMove()
  DrawingArea1.X += Mouse.X - Mouse.StartX
  DrawingArea1.Y += Mouse.Y - Mouse.StartY
End

'----------------------------------------------


Regards,
Werner




More information about the User mailing list