<html>
<head>
<title>Using ImageButton as an Image Map</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server">
void getClickCoords ( object src, ImageClickEventArgs e ) {
int x = e.X;
int y = e.Y;
Label1.Text = "X:" + x.ToString ( );
Label2.Text = "Y:" + y.ToString ( );
imgButt.ImageUrl = "~/shared/images/billg.gif";
// Check to see if an eye, ear, nose or mouth was clicked.
if ( x>20 && x<35 && y>72 && y<88 ) {
message.Text = "That was Bill’s ear you clicked.";
}
else if ( x>42 && x<62 && y>48 && y<64 ) {
message.Text = "That was Bill’s eye you nicked.";
}
else if ( x>62 && x<90 ) {
if ( y>46 && y<56 ) {
message.Text = "That was Bill’s eye you nicked.";
}
else if ( y<75 && y>60 ) {
message.Text = "That was Bill’s nose you picked.";
}
else if ( y<90 && y>75 ) {
message.Text = "That was Bill’s mouth you picked.";
}
else {
whoops ( );
}
}
else if ( x>100 && x<108 && y>56 && y<72 ) {
message.Text = "That was Bill’s ear you clicked.";
}
else {
whoops ( );
}
}
void whoops ( ) {
imgButt.ImageUrl = "~/shared/images/billg_tongue.gif";
message.Text = "Bwaaahaaahaa! You missed! Try again.";
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc -->
<div class="header"><h2>Using ImageButton as an Image Map</h2></div>
<!-- #include virtual="~/shared/viewsrc_top.inc" -->
<hr size=1 width=92%>
<div align="center">
<form runat="server">
<table cellpadding=5>
<tr align="center">
<td><b><asp:label id="Label1" text="X:" runat="server" />
<asp:label id="Label2" text="Y:" runat="server" /></b></td>
<tr>
<td>
<asp:imagebutton id="imgButt"
imageurl="/shared/images/billg.gif"
onClick="getClickCoords"
runat="server" /></td></tr>
</table>
<asp:label id="message" font-bold runat="server" />
</form>
</div>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>