ARTICLE

Trace Mouse Coordinate in ASP.NET

Posted by Abhimanyu Kumar Vatsa Articles | ASP.NET using VB.NET June 07, 2010
In this article we will discuss how to trace the mouse location on page.
 
Reader Level:

Introduction

As we have seen in many windows applications, basically in drawing applications like CorelDraw, displays the coordinate location of mouse. When we move our mouse it frequently changes its location. But we never seen such in ASP.Net like web applications. It is very easy to trace the mouse location in ASP.Net. Let's take a look at simple project code to create it.

Development

In this project, we have only a Default.aspx page and we will write the codes in the body section of the page under div tag. Here it is given

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Display Mouse Coordinate</title>
</head>
<
body>
<
form id="form1" runat="server">
<div>

<div id="mouse_location">
<strong><span style="color: #0000ff">Look at the Status Bar to see the location of your mouse.
<script type="text/javascript">
function location_trap(e)
{
if (document.layers)
{
xCoord = e.x;
yCoord = e.y;
}
else if (document.all)
{
xCoord = event.clientX;
yCoord = event.clientY;
}
else if (document.getElementById)
{
xCoord = e.clientX;
yCoord = e.clientY;
}
self.status = "Location X: "+ xCoord + " and Location Y: " + yCoord;
}
document.onmousemove = location_trap;
if(document.captureEvents)
{
document.captureEvents(Event.MOUSEMOVE);
}
</script>

</span></strong>
</
div>

</div>
</
form>
</
body>
</html>

After writing the above codes we can see our mouse coordinte location in Status Bar of the web page. Here is screenshort given

1.JPG

HAVE A GREAT COADING !
 

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor