RectangleHotSpot.Top 属性
定义
获取或设置矩形区域顶边的 y 坐标,该矩形区域由此 RectangleHotSpot 对象定义。Gets or sets the y-coordinate of the top side of the rectangular region defined by this RectangleHotSpot object.
public:
property int Top { int get(); void set(int value); };
public int Top { get; set; }
member this.Top : int with get, set
Public Property Top As Integer
属性值
矩形区域顶边的 y 坐标,该矩形区域由此 RectangleHotSpot 对象定义。The y-coordinate of the top side of the rectangular region defined by this RectangleHotSpot object. 默认值为 0。The default is 0.
示例
下面的代码示例演示如何以声明方式创建 ImageMap 包含两个对象的控件 RectangleHotSpot 。The following code example demonstrates how to declaratively create an ImageMap control that contains two RectangleHotSpot objects. 以 RectangleHotSpot 声明方式创建一个对象,并 Top 以声明方式设置其属性,包括属性。One RectangleHotSpot object is created declaratively and its properties, including the Top property, are set declaratively. 其他 RectangleHotSpot 对象是以编程方式创建的,它的属性(包括 Top 属性)以编程方式进行设置。The other RectangleHotSpot object is created programmatically and its properties, including the Top property, are set programmatically. 若要使此示例正常工作,必须为属性提供自己的图像 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 Page_Load(object sender, EventArgs e)
{
// Programmatically create a RectangleHotSpot.
RectangleHotSpot Rectangle1 = new RectangleHotSpot();
// Set properties on Rectangle1.
Rectangle1.Top = 0;
Rectangle1.Left = 0;
Rectangle1.Bottom = 200;
Rectangle1.Right = 200;
Rectangle1.PostBackValue = "Yes";
Rectangle1.AlternateText = "Vote yes";
// Add the RectangleHotSpot object to the
// Vote ImageMap control's HotSpotCollection.
Vote.HotSpots.Add(Rectangle1);
}
void VoteMap_Clicked(object sender, ImageMapEventArgs e)
{
// When a user clicks the "Yes" hot spot,
// display the hot spot's value.
if (e.PostBackValue == "Yes")
Message1.Text = "You selected " + e.PostBackValue + ".";
else if (e.PostBackValue == "No")
// When a user clicks the "No" hot spot,
// display the hot spot's value.
Message1.Text = "You selected " + e.PostBackValue + ".";
else
Message1.Text = "You did not click a valid hot spot region.";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>RectangleHotSpot Properties Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>RectangleHotSpot Properties Example</h3>
<!-- Change or remove the width and height attributes as
appropriate for your image. -->
<asp:imagemap id="Vote"
imageurl="Images/VoteImage.jpg"
alternatetext="Voting choices"
hotspotmode="PostBack"
width="400"
height="200"
onclick="VoteMap_Clicked"
runat="Server">
<asp:RectangleHotSpot
top="0"
left="201"
bottom="200"
right="400"
postbackvalue="No"
alternatetext="Vote no">
</asp:RectangleHotSpot>
</asp:imagemap>
<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 RectangleHotSpot.
Dim Rectangle1 As New RectangleHotSpot
' Set properties on Rectangle1.
Rectangle1.Top = 0
Rectangle1.Left = 0
Rectangle1.Bottom = 200
Rectangle1.Right = 200
Rectangle1.PostBackValue = "Yes"
Rectangle1.AlternateText = "Vote yes"
' Add the RectangleHotSpot object to the
' Vote ImageMap control's HotSpotCollection.
Vote.HotSpots.Add(Rectangle1)
End Sub
Sub VoteMap_Clicked(ByVal sender As Object, ByVal e As ImageMapEventArgs)
' When a user clicks the "Yes" hot spot,
' display the hot spot's value.
If (e.PostBackValue = "Yes") Then
Message1.Text = "You selected " & e.PostBackValue & "."
' When a user clicks the "No" hot spot,
' display the hot spot's value.
ElseIf (e.PostBackValue = "No") Then
Message1.Text = "You selected " & e.PostBackValue & "."
Else
Message1.Text = "You did not click a valid hot spot region."
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>RectangleHotSpot Properties Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>RectangleHotSpot Properties Example</h3>
<!-- Change or remove the width and height attributes as
appropriate for your image. -->
<asp:imagemap id="Vote"
imageurl="Images/VoteImage.jpg"
alternatetext="Voting choices"
hotspotmode="PostBack"
width="400"
height="200"
onclick="VoteMap_Clicked"
runat="Server">
<asp:RectangleHotSpot
top="0"
left="201"
bottom="200"
right="400"
postbackvalue="No"
alternatetext="Vote no">
</asp:RectangleHotSpot>
</asp:imagemap>
<br />
<asp:label id="Message1"
runat="Server">
</asp:label>
</form>
</body>
</html>
注解
Top属性允许您获取或设置一个值,该值表示此对象所定义的矩形区域顶边的 y 坐标 RectangleHotSpot 。The Top property allows you to get or set a value that represents the y-coordinate of the top side of the rectangular region defined by this RectangleHotSpot object. 完全定义 RectangleHotSpot 对象。To completely define a RectangleHotSpot object. 您必须为此属性和 Left 、和属性指定一个值 Right Bottom 。you must specify a value for this property and for the Left, Right, and Bottom properties.