Gambas/Mouse

The Mouse Coordinate Program
This program will show the coordinates of the mousepointer continuously in two textboxes, when the left mousebutton is pressed. You need a form with a drawingarea and two textboxes to get the program going. See how it looks like here: http://www.madeasy.de/7/prgmausxy1.htm

The upper left corner of the drawing area has the coordinates (0,0). The right lower corner has the coordinates (drawingArea1.width, drawingarea1.height )

The Code

PUBLIC SUB DrawingArea1_MouseMove Textbox1.text = Mouse.X Textbox2.text = Mouse.Y  END

You can simplify the program, when you work without the drawingarea. The code should look like this.

PUBLIC SUB Form1_MouseMove Textbox1.text = Mouse.X Textbox2.text = Mouse.Y  END

Try it out !

We can even get rid of the textboxes using the print command instead. Then the coordinates appear in the terminal window.

The code should look like this.

PUBLIC SUB Form1_MouseMove PRINT mouse.X PRINT Mouse.Y  END

Try it out !

Be aware that the DrawingArea is the only control in Gambas ( at current version 2.n) that tracks mouse movement. Other controls will only provide Mouse coordinates on the Mouse down event. Additionally they have ENTER and LEAVE functions which provide the 'Mouse Over' functionality.