PolygonHotSpot.Coordinates 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示 PolygonHotSpot 对象顶点的坐标的字符串。
public:
property System::String ^ Coordinates { System::String ^ get(); void set(System::String ^ value); };
public string Coordinates { get; set; }
member this.Coordinates : string with get, set
Public Property Coordinates As String
属性值
表示 PolygonHotSpot 对象的顶点坐标的字符串。
示例
下面的代码示例演示如何以编程方式创建 PolygonHotSpot 对象并将其添加到 ImageMap 控件。 属性 Coordinates 用于指定 对象的顶点的 PolygonHotSpot 坐标。 控件 ImageMap 包含以声明方式添加的其他 PolygonHotSpot 两个对象。 每个 PolygonHotSpot 对象都表示地图上的一个地理区域。 当用户单击对象时 PolygonHotSpot ,它会发回服务器,热点的类型和名称将显示在标签中。
<%@ 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 Page_Load(object sender, EventArgs e)
{
// Programmatically create a PolygonHotSpot.
PolygonHotSpot Polygon1 = new PolygonHotSpot();
Polygon1.Coordinates = "128,185,335,157,400,224,400,400,228,400";
Polygon1.PostBackValue = "Southern";
Polygon1.AlternateText = "Southern Region";
// Add it to the end of the ImageMap control's
// HotSpotCollection.
Regions.HotSpots.Add(Polygon1);
}
void RegionMap_Clicked (object sender, ImageMapEventArgs e)
{
string hotSpotType;
// When a user clicks a hot spot, display
// the hot spot's type and name.
switch (e.PostBackValue)
{
case "Western":
hotSpotType = Regions.HotSpots[0].ToString();
Message1.Text = "You selected " + hotSpotType + " " + e.PostBackValue;
break;
case "Northern":
hotSpotType = Regions.HotSpots[1].ToString();
Message1.Text = "You selected " + hotSpotType + " " + e.PostBackValue;
break;
case "Southern":
hotSpotType = Regions.HotSpots[2].ToString();
Message1.Text = "You selected " + hotSpotType + " " + e.PostBackValue;
break;
default:
Message1.Text = "You did not click a valid hot spot region.";
break;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>PolygonHotSpot Constructor Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>PolygonHotSpot Constructor Example</h3>
<!-- Change or remove the width and height attributes as
appropriate for your image. -->
<asp:imagemap id="Regions"
imageurl="Images/RegionMap.jpg"
alternatetext="Sales regions"
hotspotmode="PostBack"
width="400"
height="400"
onclick="RegionMap_Clicked"
runat="Server">
<asp:PolygonHotSpot
coordinates="0,0,176,0,125,182,227,400,0,400"
postbackvalue="Western"
alternatetext="Western Region">
</asp:PolygonHotSpot>
<asp:PolygonHotSpot
coordinates="177,0,400,0,400,223,335,154,127,180"
postbackvalue="Northern"
alternatetext="Northern Region">
</asp:PolygonHotSpot>
</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 Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Programmatically create a PolygonHotSpot.
Dim Polygon1 As New PolygonHotSpot
Polygon1.Coordinates = "128,185,335,157,400,224,400,400,228,400"
Polygon1.PostBackValue = "Southern"
Polygon1.AlternateText = "Southern Region"
' Add it to the end of the ImageMap control's
' HotSpotCollection.
Regions.HotSpots.Add(Polygon1)
End Sub
Sub RegionMap_Clicked(ByVal sender As Object, ByVal e As ImageMapEventArgs)
Dim hotSpotType As String
' When a user clicks a hot spot, display
' the hot spot's type and name.
Select Case (e.PostBackValue)
Case ("Western")
hotSpotType = Regions.HotSpots(0).ToString()
Message1.Text = "You selected " & hotSpotType & " " & e.PostBackValue
Case ("Northern")
hotSpotType = Regions.HotSpots(1).ToString()
Message1.Text = "You selected " & hotSpotType & " " & e.PostBackValue
Case ("Southern")
hotSpotType = Regions.HotSpots(2).ToString()
Message1.Text = "You selected " & hotSpotType & " " & e.PostBackValue
Case Else
Message1.Text = "You did not click a valid hot spot region."
End Select
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>PolygonHotSpot Constructor Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>PolygonHotSpot Constructor Example</h3>
<!-- Change or remove the width and height attributes as
appropriate for your image. -->
<asp:imagemap id="Regions"
imageurl="Images/RegionMap.jpg"
alternatetext="Sales regions"
hotspotmode="PostBack"
width="400"
height="400"
onclick="RegionMap_Clicked"
runat="Server">
<asp:PolygonHotSpot
coordinates="0,0,176,0,125,182,227,400,0,400"
postbackvalue="Western"
alternatetext="Western Region">
</asp:PolygonHotSpot>
<asp:PolygonHotSpot
coordinates="177,0,400,0,400,223,335,154,127,180"
postbackvalue="Northern"
alternatetext="Northern Region">
</asp:PolygonHotSpot>
</asp:imagemap>
<br /><br />
<asp:label id="Message1"
runat="Server">
</asp:label>
</form>
</body>
</html>
注解
Coordinates使用 属性可以指定 对象的顶点的PolygonHotSpot坐标。 多边形顶点是两个多边形边缘相交的点。 指定的字符串的格式必须用逗号分隔的每个坐标。 指定的每个顶点必须同时具有 x 坐标和 y 坐标。 例如,字符串“128,185,335,157,510,224,510,383,228,383”定义具有五个顶点的多边形热点。 第一个顶点的 x 坐标为 128。 第一个顶点的 y 坐标为 185。