Share via


RectangleHotSpot.GetCoordinates Méthode

Définition

Retourne une chaîne qui représente les coordonnées x et y du coin supérieur gauche d'un objet RectangleHotSpot et les coordonnées x et y de son coin inférieur droit.

public:
 override System::String ^ GetCoordinates();
public override string GetCoordinates ();
override this.GetCoordinates : unit -> string
Public Overrides Function GetCoordinates () As String

Retours

String

Chaîne qui représente les coordonnées x et y du coin supérieur gauche d'un objet RectangleHotSpot et les coordonnées x et y de son coin inférieur droit.

Exemples

L’exemple de code suivant montre comment créer de manière déclarative un ImageMap contrôle qui contient deux RectangleHotSpot objets. La ImageMap.HotSpotMode propriété est définie HotSpotMode.PostBacksur , ce qui entraîne la publication de la page sur le serveur chaque fois qu’un utilisateur clique sur l’une des régions à chaud. Chaque fois que l’utilisateur clique sur l’un des RectangleHotSpot objets, la GetCoordinates méthode est appelée et les coordonnées du point chaud sélectionné sont affichées à l’utilisateur. Pour que cet exemple fonctionne correctement, vous devez fournir votre propre image pour la ImageUrl propriété et mettre à jour le chemin d’accès à l’image de manière appropriée afin que l’application puisse la localiser.

<%@ 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>

Remarques

Cette méthode retourne une chaîne qui représente les coordonnées du coin supérieur gauche d’un RectangleHotSpot objet et les coordonnées de son coin inférieur droit. Cette méthode utilise les valeurs affectées aux Left propriétés et Top aux propriétés pour retourner les coordonnées du coin supérieur gauche. Il utilise les valeurs affectées aux Right propriétés et Bottom aux propriétés pour retourner les coordonnées pour le coin inférieur droit.

La GetCoordinates méthode est utilisée en interne par ASP.NET pour obtenir le texte à utiliser pour les coordonnées d’un RectangleHotSpot rendu. La chaîne retournée est spécifique au navigateur et au langage de balisage.

S’applique à

Voir aussi