MouseEventArgs.Location Property
Gets the location of the mouse during the generating mouse event.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
The following code example uses the Location property to track left mouse clicks and draw a series of straight line segments in response to user input. The example does not persist the drawn lines if you hide the form and then redisplay it; this code has been omitted for simplicity.
Point firstPoint; Boolean haveFirstPoint; public void EnableDrawing() { this.MouseDown += new MouseEventHandler(Form1_MouseDownDrawing); } void Form1_MouseDownDrawing(object sender, System.Windows.Forms.MouseEventArgs e) { if (haveFirstPoint) { Graphics g = this.CreateGraphics(); g.DrawLine(Pens.Black, firstPoint, e.Location); haveFirstPoint = false; } else { firstPoint = e.Location; haveFirstPoint = true; } }
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.