RectangleHotSpot Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Defines a rectangular hot spot region in an ImageMap control. This class cannot be inherited.
public ref class RectangleHotSpot sealed : System::Web::UI::WebControls::HotSpot
public sealed class RectangleHotSpot : System.Web.UI.WebControls.HotSpot
type RectangleHotSpot = class
inherit HotSpot
Public NotInheritable Class RectangleHotSpot
Inherits HotSpot
- Inheritance
Examples
The following code example demonstrates how to declaratively create an ImageMap control that contains two RectangleHotSpot objects. The ImageMap.HotSpotMode property is set to HotSpotMode.PostBack
, which causes the page to post back to the server each time a user clicks one of the hot spot regions. Each time the user clicks one of the RectangleHotSpot objects, the GetCoordinates method is called and the coordinates of the selected hot spot are displayed to the user. For this example to work correctly, you must supply your own image for the ImageUrl property and update the path to the image appropriately so that the application can locate it.
<%@ page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void VoteMap_Clicked (Object sender, ImageMapEventArgs e)
{
string coordinates;
string hotSpotType;
int yescount = ((ViewState["yescount"] != null)? (int)ViewState["yescount"] : 0);
int nocount = ((ViewState["nocount"] != null)? (int)ViewState["nocount"] : 0);
// When a user clicks the "Yes" hot spot,
// display the hot spot's name and coordinates.
if (e.PostBackValue.Contains("Yes"))
{
yescount += 1;
coordinates = Vote.HotSpots[0].GetCoordinates();
hotSpotType = Vote.HotSpots[0].ToString ();
Message1.Text = "You selected " + hotSpotType + " " + e.PostBackValue + ".<br />" +
"The coordinates are " + coordinates + ".<br />" +
"The current vote count is " + yescount.ToString() +
" yes votes and " + nocount.ToString() + " no votes.";
}
// When a user clicks the "No" hot spot,
// display the hot spot's name and coordinates.
else if (e.PostBackValue.Contains("No"))
{
nocount += 1;
coordinates = Vote.HotSpots[1].GetCoordinates();
hotSpotType = Vote.HotSpots[1].ToString ();
Message1.Text = "You selected " + hotSpotType + " " + e.PostBackValue + ".<br />" +
"The coordinates are " + coordinates + ".<br />" +
"The current vote count is " + yescount.ToString() +
" yes votes and " + nocount.ToString() + " no votes.";
}
else
{
Message1.Text = "You did not click a valid hot spot region.";
}
ViewState["yescount"] = yescount;
ViewState["nocount"] = nocount;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1" runat="server">
<title>ImageMap Class Post Back Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>ImageMap Class Post Back Example</h3>
<asp:imagemap id="Vote"
imageurl="Images/VoteImage.jpg"
width="400"
height="200"
alternatetext="Vote Yes or No"
hotspotmode="PostBack"
onclick="VoteMap_Clicked"
runat="Server">
<asp:RectangleHotSpot
top="0"
left="0"
bottom="200"
right="200"
postbackvalue="Yes"
alternatetext="Vote yes">
</asp:RectangleHotSpot>
<asp:RectangleHotSpot
top="0"
left="201"
bottom="200"
right="400"
postbackvalue="No"
alternatetext="Vote no">
</asp:RectangleHotSpot>
</asp:imagemap>
<br /><br />
<asp:label id="Message1"
runat="Server">
</asp:label>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub VoteMap_Clicked(ByVal sender As Object, ByVal e As ImageMapEventArgs)
Dim coordinates As String
Dim hotSpotType As String
Dim yescount As Integer
Dim nocount As Integer
If (ViewState("yescount") IsNot Nothing) Then
yescount = Convert.ToInt32(ViewState("yescount"))
Else
yescount = 0
End If
If (ViewState("nocount") IsNot Nothing) Then
nocount = Convert.ToInt32(ViewState("nocount"))
Else
nocount = 0
End If
' When a user clicks the "Yes" hot spot,
' display the hot spot's name and coordinates.
If (e.PostBackValue.Contains("Yes")) Then
yescount += 1
coordinates = Vote.HotSpots(0).GetCoordinates()
hotSpotType = Vote.HotSpots(0).ToString()
Message1.Text = "You selected " & hotSpotType & " " & e.PostBackValue & ".<br />" & _
"The coordinates are " & coordinates & ".<br />" & _
"The current vote count is " & yescount.ToString() & _
" yes votes and " & nocount.ToString() & " no votes."
' When a user clicks the "No" hot spot,
' display the hot spot's name and coordinates.
ElseIf (e.PostBackValue.Contains("No")) Then
nocount += 1
coordinates = Vote.HotSpots.Item(1).GetCoordinates()
hotSpotType = Vote.HotSpots.Item(1).ToString()
Message1.Text = "You selected " & hotSpotType & " " & e.PostBackValue & ".<br />" & _
"The coordinates are " & coordinates & ".<br />" & _
"The current vote count is " & yescount.ToString() & _
" yes votes and " & nocount.ToString() & " no votes."
Else
Message1.Text = "You did not click a valid hot spot region."
End If
ViewState("yescount") = yescount
ViewState("nocount") = nocount
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1" runat="server">
<title>ImageMap Class Post Back Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>ImageMap Class Post Back Example</h3>
<asp:imagemap id="Vote"
imageurl="Images/VoteImage.jpg"
width="400"
height="200"
alternatetext="Vote Yes or No"
hotspotmode="PostBack"
onclick="VoteMap_Clicked"
runat="Server">
<asp:RectangleHotSpot
top="0"
left="0"
bottom="200"
right="200"
postbackvalue="Yes"
alternatetext="Vote yes">
</asp:RectangleHotSpot>
<asp:RectangleHotSpot
top="0"
left="201"
bottom="200"
right="400"
postbackvalue="No"
alternatetext="Vote no">
</asp:RectangleHotSpot>
</asp:imagemap>
<br /><br />
<asp:label id="Message1"
runat="Server">
</asp:label>
</form>
</body>
</html>
Remarks
This class defines a rectangular hot spot region in an ImageMap control. To define the region of the RectangleHotSpot object, set the Left property to the value that represents the x-coordinate of the rectangular region's top left corner. Set the Top property to the value that represents the y-coordinate of the rectangular region's top left corner. Set the Right property to the value that represents the x-coordinate of the rectangular region's bottom right corner. Set of the Bottom property to the value that represents the y-coordinate of the rectangular region's bottom right corner.
When a RectangleHotSpot control is clicked, the page navigates to a URL, generates a post back to the server, or does nothing. The HotSpotMode property specifies this behavior. To navigate to a URL, set the HotSpotMode property to HotSpotMode.Navigate
and use the NavigateUrl property to specify the URL to navigate to. To post back to the server, set the HotSpotMode property to HotSpotMode.PostBack
and use the PostBackValue property to specify a name for the RectangleHotSpot object. This name will be passed in the ImageMapEventArgs event data when the RectangleHotSpot is clicked. . If you want the HotSpot object to have no behavior, set the HotSpotMode property to HotSpotMode.Inactive
.
Constructors
RectangleHotSpot() |
Initializes a new instance of the RectangleHotSpot class. |
Properties
AccessKey |
Gets or sets the access key that allows you to quickly navigate to the HotSpot region. (Inherited from HotSpot) |
AlternateText |
Gets or sets the alternate text to display for a HotSpot object in an ImageMap control when the image is unavailable or renders to a browser that does not support images. (Inherited from HotSpot) |
Bottom |
Gets or sets the y-coordinate of the bottom side of the rectangular region defined by this RectangleHotSpot object. |
HotSpotMode |
Gets or sets the behavior of a HotSpot object in an ImageMap control when the HotSpot is clicked. (Inherited from HotSpot) |
IsTrackingViewState |
Gets a value indicating whether the HotSpot object is tracking its view-state changes. (Inherited from HotSpot) |
Left |
Gets or sets the x-coordinate of the left side of the rectangular region defined by this RectangleHotSpot object. |
MarkupName |
When overridden in a derived class, gets the string representation for the HotSpot object's shape. (Inherited from HotSpot) |
NavigateUrl |
Gets or sets the URL to navigate to when a HotSpot object is clicked. (Inherited from HotSpot) |
PostBackValue |
Gets or sets the name of the HotSpot object to pass in the event data when the HotSpot is clicked. (Inherited from HotSpot) |
Right |
Gets or sets the x-coordinate of the right side of the rectangular region defined by this RectangleHotSpot object. |
TabIndex |
Gets or sets the tab index of the HotSpot region. (Inherited from HotSpot) |
Target |
Gets or sets the target window or frame in which to display the Web page content linked to when a HotSpot object that navigates to a URL is clicked. (Inherited from HotSpot) |
Top |
Gets or sets the y-coordinate of the top side of the rectangular region defined by this RectangleHotSpot object. |
ViewState |
Gets a dictionary of state information that allows you to save and restore the view state of a HotSpot object across multiple requests for the same page. (Inherited from HotSpot) |
Methods
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
GetCoordinates() |
Returns a string that represents the x -and y-coordinates of a RectangleHotSpot object's top left corner and the x- and y-coordinates of its bottom right corner. |
GetHashCode() |
Serves as the default hash function. (Inherited from Object) |
GetType() |
Gets the Type of the current instance. (Inherited from Object) |
LoadViewState(Object) |
Restores the HotSpot object's previously saved view state to the object. (Inherited from HotSpot) |
MemberwiseClone() |
Creates a shallow copy of the current Object. (Inherited from Object) |
SaveViewState() |
Saves the changes to the HotSpot object's view state since the time the page was posted back to the server. (Inherited from HotSpot) |
ToString() |
Returns the String representation of this instance of a HotSpot object. (Inherited from HotSpot) |
TrackViewState() |
Causes the HotSpot object to track changes to its view state so they can be stored in the object's StateBag object. This object is accessible through the ViewState property. (Inherited from HotSpot) |
Explicit Interface Implementations
IStateManager.IsTrackingViewState |
Gets a value indicating whether the HotSpot object is tracking its view-state changes. (Inherited from HotSpot) |
IStateManager.LoadViewState(Object) |
Restores the HotSpot object's previously saved view state to the object. (Inherited from HotSpot) |
IStateManager.SaveViewState() |
Saves the changes to the HotSpot object's view state since the last time the page was posted back to the server. (Inherited from HotSpot) |
IStateManager.TrackViewState() |
Instructs the HotSpot region to track changes to its view state. (Inherited from HotSpot) |