To display the image in the ImageMap control, set its ImageURL property to point to the file you just saved (
Images/dellaxim.jpg
). The ImageMap control will now display the image of a Pocket PC, as shown in Figure 1-32.
An image map works by providing one or more hotspots for users to click on, each initiating a particular actionfor example, jumping to another page or altering the image itself. To define one or more hotspots, go to the Properties window for the ImageMap control, scroll down to the Hotspots property, and click on the Collections button (...) to invoke the HotSpot Collection Editor (shown in Figure 1-33).
The ImageMap control supports three kinds of hotspot: circles (
CircleHotSpot
), rectangles (
RectangleHotSpot
), and polygons (
PolygonHotSpot
). The drop-down menu to the right of the dialog's Add button dialog lets you choose the type of hotspot to add. Once you add a hotspot, a Properties window appears that allows you to specify the location and dimensions of the hotspot, as well as its key properties. Figure 1-33 displays the properties of a
CircleHotSpot
that has a radius of
5
and
x
and
y
coordinates of
103
and
26
, respectively.
You can also specify your hotspots by hand. You can switch to Source View and add in the hotspots elements manually, like this:
<asp:ImageMap ID="ImageMap1" runat="server"
ImageUrl="Images/dellaxim.jpg">
<asp:CircleHotSpot HotSpotMode="PostBack"
X="103" Y="26" PostBackValue="PowerSwitch"
Radius="5" />
<asp:RectangleHotSpot Top="48" Bottom="242"
Left="30" NavigateUrl="./screen.aspx"
Right="177" />
<asp:PolygonHotSpot
Coordinates="92,273,112,273,123,287,112,303,92,303,83,287"
PostBackValue="Navigation" HotSpotMode="PostBack" />
</asp:ImageMap>
Tip:
You can use Microsoft Paint to display the image and then position your cursor at the various hotspots you want to define. You can find the coordinates of the cursor at the bottom of the window.
If you add the code shown in Step 6 or use the same attribute values to create hotspots with the HotSpot Collection Editor, you will end up with the hotspots shown in Figure 1-34.
Note:
The ImageMap control supports three types of hotspot: circles, rectangles, and polygons
.
Figure 1-34 shows an ImageMap with the three hotspots: a
CircleHotSpot
, a
RectangleHotSpot
, and a
PolygonHotSpot
. The
CircleHotSpot
defines the region containing the power switch of the Pocket PC as a circle hotspot, whereas the
RectangleHotSpot
defines the screen region as a rectangle hotspot. The
PolygonHotSpot
defines the navigational
buttons
on the Pocket PC as a polygon hotspot.
A HotSpot control supports one of four modes of behavior, defined by its HotSpotMode property:
-
-
Not Set
-
If a hotspot's
HotSpotMode
is set to "
Not Set
", its behavior will assume that of the
HotSpotMode
as defined in the ImageMap control.
-
-
Navigate
-
Another page can be loaded when a hotspot is clicked.
-
-
PostBack
-
A postback is sent to the server. This is useful in cases where you need to perform some action (such as increment a variable) when the
user
clicks on a hotspot.
-
-
Inactive
-
Disables the hotspot.
Tip:
The HotSpotMode property of the ImageMap control defines the default behavior of all the hotspots in that control's HotSpot collection. A particular hotspot can override this behavior by setting its own HotSpotMode property.
To
illustrate
how a hotspot can be used to postback to a server, set the HotSpotMode property of the
CircleHotSpot
to
PostBack
and the PostBackValue property value to
PowerSwitch
. To receive the postback value on the server side, add an event handler to service the click event of the ImageMap control:
Protected Sub ImageMap1_Click(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.ImageMapEventArgs) _
Handles ImageMap1.Click
Dim str As String = "You have clicked " & e.PostBackValue
Response.Write(str)
End Sub