ImageMapEventArgs Classe

Définition

Fournit des données pour l'événement Click d'un contrôle ImageMap.

public ref class ImageMapEventArgs : EventArgs
public class ImageMapEventArgs : EventArgs
type ImageMapEventArgs = class
    inherit EventArgs
Public Class ImageMapEventArgs
Inherits EventArgs
Héritage
ImageMapEventArgs

Exemples

L’exemple de code suivant montre comment créer un gestionnaire d’événements pour l’événement Click . Le ImageMap contrôle contient deux RectangleHotSpot objets. La ImageMap.HotSpotMode propriété a la HotSpotMode.PostBackvaleur , ce qui entraîne la publication de la page sur le serveur chaque fois qu’un utilisateur clique sur l’un RectangleHotSpot des objets. L’événement Click est géré par le gestionnaire d’événements VoteMap_Clicked . Le VoteMap_Clicked examine la PostBackValue propriété, envoyée dans les ImageMapEventArgs données, pour déterminer quel RectangleHotSpot objet est associé à l’événement. 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;
    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>

Remarques

L’événement Click est déclenché lorsqu’un utilisateur clique sur un HotSpot objet dans un ImageMap contrôle. Pour permettre à un HotSpot objet de déclencher l’événement Click , vous devez d’abord définir la ImageMap.HotSpotMode propriété ou la propriété sur HotSpot.HotSpotModeHotSpotMode.PostBack. Pour contrôler les actions effectuées par programmation lors d’un clic sur une publication HotSpot , fournissez un gestionnaire d’événements pour l’événement Click .

Une PostBackValue propriété stocke une chaîne associée au comportement de l’objet HotSpot lorsqu’on clique dessus. Cette chaîne est passée dans les données d’événement ImageMapEventArgs lorsque l’utilisateur HotSpot clique sur .

Constructeurs

ImageMapEventArgs(String)

Initialise une nouvelle instance de la classe ImageMapEventArgs.

Propriétés

PostBackValue

Obtient le String assigné à la propriété PostBackValue de l'objet HotSpot sur lequel un clic a été effectué.

Méthodes

Equals(Object)

Détermine si l'objet spécifié est égal à l'objet actuel.

(Hérité de Object)
GetHashCode()

Fait office de fonction de hachage par défaut.

(Hérité de Object)
GetType()

Obtient le Type de l'instance actuelle.

(Hérité de Object)
MemberwiseClone()

Crée une copie superficielle du Object actuel.

(Hérité de Object)
ToString()

Retourne une chaîne qui représente l'objet actuel.

(Hérité de Object)

S’applique à

Voir aussi