RectangleHotSpot 类

定义

ImageMap 控件中定义矩形作用点区域。 此类不能被继承。

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

示例

下面的代码示例演示如何以声明方式创建包含两RectangleHotSpotImageMap 对象的控件。 属性 ImageMap.HotSpotMode 设置为 HotSpotMode.PostBack,这会导致每次用户单击某个热点区域时,页面都会发回服务器。 用户每次单击其中 RectangleHotSpot 一个对象时 GetCoordinates ,都会调用 方法,并将所选热点的坐标显示给用户。 若要使此示例正常工作,必须为 属性提供自己的映像 ImageUrl ,并相应地更新映像的路径,以便应用程序能够找到它。

<%@ 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 矩形热点区域。 若要定义对象的区域 RectangleHotSpot ,请将 Left 属性设置为表示矩形区域左上角的 x 坐标的值。 将 Top 属性设置为表示矩形区域左上角的 y 坐标的值。 将 Right 属性设置为表示矩形区域右下角的 x 坐标的值。 Bottom将 属性设置为表示矩形区域右下角的 y 坐标的值。

RectangleHotSpot单击控件时,页面会导航到 URL,生成回服务器的帖子,或者不执行任何操作。 属性 HotSpotMode 指定此行为。 若要导航到 URL,请将 HotSpotMode 属性 HotSpotMode.Navigate 设置为 ,并使用 NavigateUrl 属性指定要导航到的 URL。 若要回发到服务器,请将 HotSpotMode 属性设置为 HotSpotMode.PostBack ,并使用 PostBackValue 属性指定 RectangleHotSpot 对象的名称。 单击 时RectangleHotSpotImageMapEventArgs将在事件数据中传递此名称。 . 如果希望对象 HotSpot 没有行为,请将 属性 HotSpotMode 设置为 HotSpotMode.Inactive

构造函数

RectangleHotSpot()

初始化 RectangleHotSpot 类的新实例。

属性

AccessKey

获取或设置使您可以快速导航至 HotSpot 区域的访问键。

(继承自 HotSpot)
AlternateText

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

(继承自 HotSpot)
Bottom

获取或设置矩形区域底边的 y 坐标,该矩形区域由此 RectangleHotSpot 对象定义。

HotSpotMode

获取或设置单击 HotSpot 控件中的 ImageMap 对象时 HotSpot 的行为。

(继承自 HotSpot)
IsTrackingViewState

获取一个值,该值指示 HotSpot 对象是否跟踪其视图状态更改。

(继承自 HotSpot)
Left

获取或设置矩形区域左边的 x 坐标,该矩形区域由此 RectangleHotSpot 对象定义。

MarkupName

在派生类中重写时,获取 HotSpot 对象的形状的字符串表示形式。

(继承自 HotSpot)
NavigateUrl

获取或设置单击 HotSpot 对象时导航至的 URL。

(继承自 HotSpot)
PostBackValue

获取或设置在单击 HotSpot 时在事件数据中传递的 HotSpot 对象名称。

(继承自 HotSpot)
Right

获取或设置矩形区域右边的 x 坐标,该矩形区域由此 RectangleHotSpot 对象定义。

TabIndex

获取或设置 HotSpot 区域的选项卡索引。

(继承自 HotSpot)
Target

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

(继承自 HotSpot)
Top

获取或设置矩形区域顶边的 y 坐标,该矩形区域由此 RectangleHotSpot 对象定义。

ViewState

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

(继承自 HotSpot)

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetCoordinates()

返回一个字符串,该字符串表示 RectangleHotSpot 对象左上角和右下角的 x 坐标和 y 坐标。

GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
LoadViewState(Object)

HotSpot 对象以前保存的视图状态还原到该对象。

(继承自 HotSpot)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
SaveViewState()

自页回发到服务器开始,将更改保存到 HotSpot 对象的视图状态。

(继承自 HotSpot)
ToString()

返回 String 对象的此实例的 HotSpot 表示形式。

(继承自 HotSpot)
TrackViewState()

使 HotSpot 对象跟踪对其视图状态所做的更改,以便可以将这些更改存储在该对象的 StateBag 对象中。 通过 ViewState 属性可访问此对象。

(继承自 HotSpot)

显式接口实现

IStateManager.IsTrackingViewState

获取一个值,该值指示 HotSpot 对象是否跟踪其视图状态更改。

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

HotSpot 对象以前保存的视图状态还原到该对象。

(继承自 HotSpot)
IStateManager.SaveViewState()

自页上次回发到服务器开始,将更改保存到 HotSpot 对象的视图状态。

(继承自 HotSpot)
IStateManager.TrackViewState()

指示 HotSpot 区域跟踪对其视图状态所做的更改。

(继承自 HotSpot)

适用于

另请参阅