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 。 按一下 時 RectangleHotSpot ,此名稱將會傳入 ImageMapEventArgs 事件資料。 . 如果您想要 HotSpot 物件沒有行為,請將 HotSpotMode 屬性設定為 HotSpotMode.Inactive

建構函式

RectangleHotSpot()

初始化 RectangleHotSpot 類別的新執行個體。

屬性

AccessKey

取得或設定可讓您快速巡覽至 HotSpot 區域的便捷鍵 (Access Key)。

(繼承來源 HotSpot)
AlternateText

取得或設定當影像無法使用或呈現至不支援影像的瀏覽器時,要針對 HotSpot 控制項中的 ImageMap 物件顯示的替代文字。

(繼承來源 HotSpot)
Bottom

取得或設定由這個 RectangleHotSpot 物件定義之矩形區域下方的 Y 軸。

HotSpotMode

取得或設定按一下 HotSpot 時,ImageMap 控制項中 HotSpot 物件的行為。

(繼承來源 HotSpot)
IsTrackingViewState

取得值,指出 HotSpot 物件是否正在追蹤它的檢視狀態變更。

(繼承來源 HotSpot)
Left

取得或設定由這個 RectangleHotSpot 物件定義之矩形區域左方的 X 軸。

MarkupName

在衍生類別中覆寫時,取得 HotSpot 物件形狀的字串表示。

(繼承來源 HotSpot)
NavigateUrl

取得或設定在按一下 HotSpot 物件時所要巡覽的 URL。

(繼承來源 HotSpot)
PostBackValue

取得或設定按一下 HotSpot 後,要傳入事件資料的 HotSpot 物件名稱。

(繼承來源 HotSpot)
Right

取得或設定由這個 RectangleHotSpot 物件定義之矩形區域右方的 X 軸。

TabIndex

取得或設定 HotSpot 區域的定位索引。

(繼承來源 HotSpot)
Target

取得或設定按一下巡覽至 URL 的 HotSpot 物件時,要顯示所連結之 Web 網頁內容的目標視窗或框架。

(繼承來源 HotSpot)
Top

取得或設定由這個 RectangleHotSpot 物件定義之矩形區域上方的 Y 軸。

ViewState

取得狀態資訊的字典,允許您在相同頁面的多個要求之間,儲存和還原 HotSpot 物件的檢視狀態。

(繼承來源 HotSpot)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetCoordinates()

傳回字串,表示 RectangleHotSpot 物件左上角的 X 和 Y 軸及其右下角的 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)

適用於

另請參閱