MouseEventArgs.Y Property (System.Windows.Forms)

Switch View :
ScriptFree
.NET Framework Class Library
MouseEventArgs.Y Property

Gets the y-coordinate of the mouse during the generating mouse event.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
Syntax

Visual Basic
Public ReadOnly Property Y As Integer
C#
public int Y { get; }
Visual C++
public:
property int Y {
	int get ();
}
F#
member Y : int

Property Value

Type: System.Int32
The y-coordinate of the mouse, in pixels.
Remarks

The mouse coordinates vary based on the event being raised. For example, when the Control.MouseMove event is handled, the mouse coordinate values are relative to the coordinates of the control that raised the event. Some events related to drag-and-drop operations have associated mouse coordinate values that are relative to the form origin or the screen origin.

Examples

The following code example uses the X and Y properties to display the current position of the mouse pointer in a ToolTip window. To use this code, call TrackCoordinates from the form constructor.

Visual Basic

Dim TrackTip As ToolTip

Private Sub TrackCoordinates()
    TrackTip = New ToolTip()
End Sub

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
    Dim TipText As String = String.Format("({0}, {1})", e.X, e.Y)
    TrackTip.Show(TipText, Me, e.Location)
End Sub


C#

ToolTip trackTip;

private void TrackCoordinates()
{
    trackTip = new ToolTip();
    this.MouseMove += new MouseEventHandler(Form1_MouseMove);
}

void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
    String tipText = String.Format("({0}, {1})", e.X, e.Y);
    trackTip.Show(tipText, this, e.Location);
}


Version Information

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
See Also

Reference

X