RectangleHotSpot.GetCoordinates Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mengembalikan string yang mewakili koordinat x -and y dari RectangleHotSpot sudut kiri atas objek dan koordinat x- dan y dari sudut kanan bawahnya.
public:
override System::String ^ GetCoordinates();
public override string GetCoordinates ();
override this.GetCoordinates : unit -> string
Public Overrides Function GetCoordinates () As String
Mengembalikan
String yang mewakili koordinat x- dan y dari RectangleHotSpot sudut kiri atas objek dan koordinat x- dan y dari sudut kanan bawahnya.
Contoh
Contoh kode berikut menunjukkan cara membuat ImageMap kontrol yang berisi dua RectangleHotSpot objek secara deklaratif. Properti ImageMap.HotSpotMode diatur ke HotSpotMode.PostBack
, yang menyebabkan halaman memposting kembali ke server setiap kali pengguna mengklik salah satu wilayah hot spot. Setiap kali pengguna mengklik salah RectangleHotSpot satu objek, metode dipanggil GetCoordinates dan koordinat hot spot yang dipilih ditampilkan kepada pengguna. Agar contoh ini berfungsi dengan benar, Anda harus menyediakan gambar Anda sendiri untuk ImageUrl properti dan memperbarui jalur ke gambar dengan tepat sehingga aplikasi dapat menemukannya.
<%@ 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;
// When a user clicks the "Yes" hot spot,
// display the hot spot's coordinates.
if (e.PostBackValue == "Yes")
{
coordinates = Vote.HotSpots[0].GetCoordinates();
Message1.Text = "The hot spot's coordinates are " + coordinates;
}
// When a user clicks the "No" hot spot,
// display the hot spot's coordinates.
else if (e.PostBackValue == "No")
{
coordinates = Vote.HotSpots[1].GetCoordinates();
Message1.Text = "The hot spot's coordinates are " + coordinates;
}
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.GetCoordinates Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>RectangleHotSpot.GetCoordinates 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="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 />
<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
' When a user clicks the "Yes" hot spot,
' display the hot spot's coordinates.
If (e.PostBackValue = "Yes") Then
coordinates = Vote.HotSpots(0).GetCoordinates()
Message1.Text = "The hot spot's coordinates are " & coordinates
' When a user clicks the "No" hot spot,
' display the hot spot's coordinates.
ElseIf (e.PostBackValue = "No") Then
coordinates = Vote.HotSpots(1).GetCoordinates()
Message1.Text = "The hot spot's coordinates are " & coordinates
Else
Message1.Text = "You did not click in 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.GetCoordinates Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>RectangleHotSpot.GetCoordinates 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="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>
Keterangan
Metode ini mengembalikan string yang mewakili koordinat RectangleHotSpot sudut kiri atas objek dan koordinat sudut kanan bawahnya. Metode ini menggunakan nilai yang ditetapkan ke Left properti dan Top untuk mengembalikan koordinat untuk sudut kiri atas. Ini menggunakan nilai yang ditetapkan ke Right properti dan Bottom untuk mengembalikan koordinat untuk sudut kanan bawah.
Metode GetCoordinates ini digunakan secara internal oleh ASP.NET untuk mendapatkan teks yang digunakan untuk koordinat RectangleHotSpot ketika dirender. String yang dikembalikan khusus untuk browser dan bahasa markup.
Berlaku untuk
Lihat juga
Saran dan Komentar
https://aka.ms/ContentUserFeedback.
Segera hadir: Sepanjang tahun 2024 kami akan menghentikan penggunaan GitHub Issues sebagai mekanisme umpan balik untuk konten dan menggantinya dengan sistem umpan balik baru. Untuk mengetahui informasi selengkapnya, lihat:Kirim dan lihat umpan balik untuk