Gambas/Mouse

From Wikibooks, the open-content textbooks collection

< Gambas
Jump to: navigation, search

Back to Gambas

[edit] The Mouse Coordinate Program

This program will show the coordinates of the mousepointer continously 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 !