Y Property
Collapse the table of content
Expand the table of content

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)

public int Y { get; }
/** @property */
public int get_Y ()

public function get Y () : int

Property Value

The y-coordinate of the mouse, in pixels.

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.

The following code example uses the X and Y properties to display the current position of the mouse pointer in a ToolTip window.

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);

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

© 2015 Microsoft