Mouse Move Code Explnation needed

Beginner

Well-known member
Joined
Mar 12, 2008
Messages
114
Programming Experience
Beginner
Regarding the following code:

Private Sub Form3_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
Coordinates.Text = "x = " & e.X - 300 & " , y = " & (-1) * (e.Y - 200)
End Sub

i quite dont get it e.X ?? what does it mean then -300 ?

When i run the program i see the limits of the x - Axis from -300 to + 300

regarding y; Why is the coding quite different than x ?

(-1) * (e.Y - 200)


Why does it say (-1).

Program works fine. I just need an explanation.
 
My guess is the -300 and -200 are the position of the control you want to detect the position on. Try to move the form around and see if the value is still right.

The minus one seems to tell that the Y position tells how far from the 200 line the Y position is, with the positives going up and negatives below...

Maybe you have a Control at 300, 200 that you want to calculate the mouse position on with the Y position starting from the bottom instead of the default top?

Edit : Actually, 200 is the bottom of the control so it is not at y = 200 itselves
 
It's the graph. -x and -y is the bottom left quadrant. x and -y is the top left, x and y is top right, -x and y is bottom right.

It's taking into account of what quadrant the mouse is in according to the graph that the lines (gears) are drawn on
 
What i dont get is the Visual Basic Part. Let me try to come again ?



Heres what i understood :
Get the mouse reading and place it at the top left corner

VB.NET:
Coordinates.Text = "x = " & e.X - 300 & " , y = " & (-1) * (e.Y - 200)



Regarding the X & Y axis. the value 2 is the thickness of the line which i understand. Studying the values of the origin
x1=300
X2=300
Y1=0
Y2=-400
That will draw the vertical line. Which im having trouble understanding.
So my frirst X value is (300) that would be all the way to the right. My second X2 is also 300 which is also all the way to the right ?? I just dont understand why we have 4 values

VB.NET:
a.DrawLine(New Pen(Color.Black, 2), 300, 0, 300, -400)
instead of 2 values in this line code.
Two to draw the vertical and another Two to draw the Horizontal Lines.
This is what im asking for.


Module code:
VB.NET:
Public bmp As New Bitmap(600, 400)which makes 300, 200


' drawing the main x-axis and y-axis, using a thicker pen


VB.NET:
a.DrawLine(New Pen(Color.Black, 2), 300, 0, 300, -400) 

a.DrawLine(New Pen(Color.Black, 2), 0, -200, 600, -200)

asvnb3.jpg
 
Last edited:
You have four values because it takes two values to describe a point. You are drawing a line between two points, pt1 and pt2. pt1 is described by its x and y location, same for pt2. You need to tell the drawline method where to stop and where to start, which is why you need both points, and thus 4 values.
 
Back
Top