Class
Point
Description
An object used to represent and work with a given Point in the coordinate system.
Methods
Name |
Parameters |
Returns |
Shared |
---|---|---|---|
Point |
|||
other As Point |
|||
Property descriptions
Point.X
X As Double
The horizontal coordinate of the Point.
This code is in the MouseDown event handler. The new mouseposition is passed as the X,Y coordinates and mouseoffset is a property of the window.
' Update our mouse position. mouseposition = New Point(x, y) ' Now we determine which rect our cursor is in ' and save the offset (how far the cursor is inside the rect) ' so when the user moves the cursor, the rect ' won't jump around. If rectone.Contains(mouseposition) Then mouseoffset.X = rectone.Origin.X - mouseposition.X mouseoffset.Y = rectone.Origin.Y - mouseposition.X draggingrect = rectone ElseIf recttwo.Contains(mouseposition) Then mouseoffset.X = recttwo.Origin.X - mouseposition.X mouseoffset.Y = recttwo.Origin.Y - mouseposition.Y draggingrect = recttwo Else mouseoffset.X = 0 mouseoffset.Y = 0 draggingrect = Nil End If ' refresh, without erasing the background Me.Refresh(False) Return True
Point.Y
Y As Double
The vertical coordinate of the Point.
This code is in the MouseDown event handler. The new mouseposition is passed as the X,Y coordinates and mouseoffset is a property of the window.
' Update our mouse position. mouseposition = New Point(x, y) ' Now we determine which rect our cursor is in ' and save the offset (how far the cursor is inside the rect) ' so when the user moves the cursor, the rect ' won't jump around. If rectone.Contains(mouseposition) Then mouseoffset.X = rectone.Origin.X - mouseposition.X mouseoffset.Y = rectone.Origin.Y - mouseposition.X draggingrect = rectone ElseIf recttwo.Contains(mouseposition) Then mouseoffset.X = recttwo.Origin.X - mouseposition.X mouseoffset.Y = recttwo.Origin.Y - mouseposition.Y draggingrect = recttwo Else mouseoffset.X = 0 mouseoffset.Y = 0 draggingrect = Nil End If ' refresh, without erasing the background Me.Refresh(False) Return True
Method descriptions
Point.Clone
Clone As Point
Creates a duplicate of the Point.
This example is in the MouseDrag event of a Rect. The object is being cloned as the way to update its position.
' Update our mouse position. mousePosition = New Point(x, y) ' If we're actually dragging something, move the rect. ' We update the rect's origin with a CLONE of the mouse position, ' because MousePosition is an instance of the Point class. ' Without the clone, when we call the offset function, we'll also update ' the MousePosition property, since both DraggingRect.Origin and MousePosition ' would point to the same variable. ' The offset function shifts the rect. Positive for right/down, ' negative for left/up. If draggingrect <> Nil Then DraggingRect.Origin = Mouseposition.Clone DraggingRect.Offset(MouseOffset.x, MouseOffset.y) End If ' refresh, without erasing the background Me.Refresh(False)
Point.Constructor
Constructor
Note
Constructors are special methods called when you create an object with the New keyword and pass in the parameters above.
Creates a Point at position (0, 0).
Point.Constructor
Constructor(X As Double, Y As Double)
Creates a basic Point with the passed coordinates.
Create a Point at 100, 50:
Var p As New Point(100, 50)
Point.DistanceTo
DistanceTo(other As Point) As Double
Calculates the distance between the Point and the passed other Point.
Var thePoint As Point = DraggingRect.Origin Var d As Double = thePoint.DistanceTo(RectTwo.Origin)
Point.Translate
Translate(deltaX As Double, deltaY As Double)
Moves the Point the given number of pixels. Positive numbers move the Point down or to the right, negative move it up or to the left.
This example is in the MouseDrag event of a Rect. The object is being cloned as the way to update its position. MouseOffset is a Point property of the window.
' Update our mouse position. mouseposition = New Point(x, y) ' If we're actually dragging something, move the rect. ' We update the rect's origin with a CLONE of the mouse position, ' because MousePosition is an instance of the Point class. ' Without the clone, when we call the offset function, we'll also update ' the MousePosition property, since both DraggingRect.Origin and MousePosition ' would point to the same variable. ' The offset function shifts the rect. Positive for right/down, ' negative for left/up. If draggingrect <> Nil Then draggingrect.Origin = mouseposition.Clone draggingrect.Offset(mouseoffset.X, mouseoffset.Y) End If ' refresh, without erasing the background Me.Refresh(False)
Compatibility
Project Types |
All |
Operating Systems |
All |
See also
Object parent class; DesktopCanvas control; DesktopWindow, DesktopContainer, Rect, Size classes.