Welcome to AspAdvice Sign in | Join | Help

AzamSharp

Some day I will know everything I hope that day never comes

Syndication

Tags

Navigation

Writing on the Screen

You can write on the screen using simple JavaScript. Take a look at the code below which is used to write on the screen using the mouse. Please note that the example below does not work on FireFox browser.

<form id="form1" runat="server">

<div>

<h2>My Canvas</h2>

<div id="canvas" style=" background-color:#FFFF99; width:300px; height:300px" onmousemove="DrawPoint(event)" onmousedown="MouseDownHandler()" onmouseup="MouseUpHandler()" onclick="DrawPoint(event)">

</div>

</div>

</form>

</body>

</html>

<script language="javascript" type="text/javascript">

var x;

var y;

var mouseState = 'up';

function MouseDownHandler()

{

mouseState = 'down';

}

function MouseUpHandler()

{

mouseState = 'up';

}

function DrawPoint(e)

{

if(mouseState == 'down')

{

var ev = e || window.event;

x = ev.clientX;

y = ev.clientY;

var divElement = document.createElement('div');

divElement.style.position = 'absolute';

divElement.style.top = y;

divElement.style.left = x;

divElement.style.backgroundColor = 'red';

var textNode = document.createTextNode('*');

divElement.appendChild(textNode);

document.body.appendChild(divElement);

}

</script>

And here is the effect.

 

 

 

Published Thursday, December 14, 2006 10:00 PM by azamsharp

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
required 
(required) 
Enter the code you see below