RectangleHotSpot 类

定义

ImageMap 控件中定义矩形作用点区域。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
继承
RectangleHotSpot

示例

下面的代码示例演示如何以声明方式创建ImageMap包含两个RectangleHotSpot对象的控件。The following code example demonstrates how to declaratively create an ImageMap control that contains two RectangleHotSpot objects. 属性设置为HotSpotMode.PostBack, 这会使页面在用户每次单击其中一个作用点区域时回发到服务器。 ImageMap.HotSpotModeThe 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. 用户每次单击其中一个RectangleHotSpot对象时GetCoordinates , 都会调用方法, 并向用户显示所选作用点的坐标。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. 若要使此示例正常工作, 必须为ImageUrl属性提供自己的图像, 并适当地更新图像的路径, 以便应用程序可以找到它。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>

注解

此类在ImageMap控件中定义矩形作用点区域。This class defines a rectangular hot spot region in an ImageMap control. 若要定义RectangleHotSpot对象的区域, 请Left将属性设置为表示矩形区域左上角的 x 坐标的值。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. Top将属性设置为表示矩形区域左上角的 y 坐标的值。Set the Top property to the value that represents the y-coordinate of the rectangular region's top left corner. Right将属性设置为表示矩形区域右下角的 x 坐标的值。Set the Right property to the value that represents the x-coordinate of the rectangular region's bottom right corner. Bottom属性集的值, 它表示矩形区域右下角的 y 坐标。Set of the Bottom property to the value that represents the y-coordinate of the rectangular region's bottom right corner.

RectangleHotSpot单击控件时, 该页面将导航到 URL, 生成回发到服务器的 post 或不执行任何操作。When a RectangleHotSpot control is clicked, the page navigates to a URL, generates a post back to the server, or does nothing. HotSpotMode属性指定此行为。The HotSpotMode property specifies this behavior. 若要导航到 URL, 请将HotSpotMode属性设置HotSpotMode.Navigate为, 并NavigateUrl使用属性指定要导航到的 URL。To navigate to a URL, set the HotSpotMode property to HotSpotMode.Navigate and use the NavigateUrl property to specify the URL to navigate to. 若要回发到服务器, 请将HotSpotMode属性设置HotSpotMode.PostBack为, 并PostBackValue使用属性指定RectangleHotSpot对象的名称。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. 当单击时ImageMapEventArgs ,此名称将在事件数据中传递。RectangleHotSpotThis name will be passed in the ImageMapEventArgs event data when the RectangleHotSpot is clicked. . 如果希望HotSpot对象没有任何行为, 请HotSpotMode将属性设置为HotSpotMode.InactiveIf you want the HotSpot object to have no behavior, set the HotSpotMode property to HotSpotMode.Inactive.

构造函数

RectangleHotSpot()

初始化 RectangleHotSpot 类的新实例。Initializes a new instance of the RectangleHotSpot class.

属性

AccessKey

获取或设置使您可以快速导航至 HotSpot 区域的访问键。Gets or sets the access key that allows you to quickly navigate to the HotSpot region.

(继承自 HotSpot)
AlternateText

获取或设置替换文字,该替换文字在图像不可用或是呈现到不支持图像的浏览器时在 HotSpot 控件中代替 ImageMap 对象显示。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.

(继承自 HotSpot)
Bottom

获取或设置矩形区域底边的 y 坐标,该矩形区域由此 RectangleHotSpot 对象定义。Gets or sets the y-coordinate of the bottom side of the rectangular region defined by this RectangleHotSpot object.

HotSpotMode

获取或设置单击 HotSpot 控件中的 ImageMap 对象时 HotSpot 的行为。Gets or sets the behavior of a HotSpot object in an ImageMap control when the HotSpot is clicked.

(继承自 HotSpot)
IsTrackingViewState

获取一个值,该值指示 HotSpot 对象是否跟踪其视图状态更改。Gets a value indicating whether the HotSpot object is tracking its view-state changes.

(继承自 HotSpot)
Left

获取或设置矩形区域左边的 x 坐标,该矩形区域由此 RectangleHotSpot 对象定义。Gets or sets the x-coordinate of the left side of the rectangular region defined by this RectangleHotSpot object.

MarkupName

在派生类中重写时,获取 HotSpot 对象的形状的字符串表示形式。When overridden in a derived class, gets the string representation for the HotSpot object's shape.

(继承自 HotSpot)
NavigateUrl

获取或设置单击 HotSpot 对象时导航至的 URL。Gets or sets the URL to navigate to when a HotSpot object is clicked.

(继承自 HotSpot)
PostBackValue

获取或设置在单击 HotSpot 时在事件数据中传递的 HotSpot 对象名称。Gets or sets the name of the HotSpot object to pass in the event data when the HotSpot is clicked.

(继承自 HotSpot)
Right

获取或设置矩形区域右边的 x 坐标,该矩形区域由此 RectangleHotSpot 对象定义。Gets or sets the x-coordinate of the right side of the rectangular region defined by this RectangleHotSpot object.

TabIndex

获取或设置 HotSpot 区域的选项卡索引。Gets or sets the tab index of the HotSpot region.

(继承自 HotSpot)
Target

获取或设置目标窗口或框架,单击导航至 URL 的 HotSpot 对象时在其中显示链接到的网页内容。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.

(继承自 HotSpot)
Top

获取或设置矩形区域顶边的 y 坐标,该矩形区域由此 RectangleHotSpot 对象定义。Gets or sets the y-coordinate of the top side of the rectangular region defined by this RectangleHotSpot object.

ViewState

获取状态信息的字典,这些信息使您可以在同一页的多个请求间保存和还原 HotSpot 对象的视图状态。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.

(继承自 HotSpot)

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetCoordinates()

返回一个字符串,该字符串表示 RectangleHotSpot 对象左上角和右下角的 x 坐标和 y 坐标。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.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
LoadViewState(Object)

HotSpot 对象以前保存的视图状态还原到该对象。Restores the HotSpot object's previously saved view state to the object.

(继承自 HotSpot)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
SaveViewState()

自页回发到服务器开始,将更改保存到 HotSpot 对象的视图状态。Saves the changes to the HotSpot object's view state since the time the page was posted back to the server.

(继承自 HotSpot)
ToString()

返回 String 对象的此实例的 HotSpot 表示形式。Returns the String representation of this instance of a HotSpot object.

(继承自 HotSpot)
TrackViewState()

使 HotSpot 对象跟踪对其视图状态所做的更改,以便可以将这些更改存储在该对象的 StateBag 对象中。Causes the HotSpot object to track changes to its view state so they can be stored in the object's StateBag object. 通过 ViewState 属性可访问此对象。This object is accessible through the ViewState property.

(继承自 HotSpot)

显式接口实现

IStateManager.IsTrackingViewState

获取一个值,该值指示 HotSpot 对象是否跟踪其视图状态更改。Gets a value indicating whether the HotSpot object is tracking its view-state changes.

(继承自 HotSpot)
IStateManager.LoadViewState(Object)

HotSpot 对象以前保存的视图状态还原到该对象。Restores the HotSpot object's previously saved view state to the object.

(继承自 HotSpot)
IStateManager.SaveViewState()

自页上次回发到服务器开始,将更改保存到 HotSpot 对象的视图状态。Saves the changes to the HotSpot object's view state since the last time the page was posted back to the server.

(继承自 HotSpot)
IStateManager.TrackViewState()

指示 HotSpot 区域跟踪对其视图状态所做的更改。Instructs the HotSpot region to track changes to its view state.

(继承自 HotSpot)

适用于

另请参阅