Writing Code in Visual Basic

Concatenation means to paste together two or more strings. We will use concatenation to display the values of both X and Y in the title. In algebra the coordinates of a point are usually displayed as X,Y. Rewrite the mouse move event to display both X and Y as shown below using the concatenation operator, &, to paste together the value of X, a string literal "," and the value of Y:

Public Class Form1
    Private Sub moving(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
        Me.Text = e.X & "," & e.Y
    End Sub
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Text = "Hello World"
    End Sub
End Class

Run the program and notice the coordinates as you move the mouse. Move the mouse to the position where you can see 0,0 as the title. Move the mouse to each edge of the form and notice the coordinates.

In the screen shot below where is the mouse? What are the coordinates of each point?

A 5,20

B 15,0

C 0,45

D 25,30

E 35,10

F 40,40 (the current mouse position)

G 45,25

Experiment: Write other procedures that display other information about an event. Try different events, and display different properties of e.

NEXT: Sender