/// <summary> /// This event is fired when an area on the right-side image map is clicked /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> /// <remarks>It receives the zero based index of the clicked area plus the /// X,Y coordinates of the clicked point within the area. This image map /// also causes validation events to fire.</remarks> protected void imClickMap_Click(object sender, ImageMapClickEventArgs e) { int clickCount = 0; if(Page.IsValid) { lblClickMsg.Text = String.Format(CultureInfo.CurrentCulture, "Clicked Area #{0}", e.AreaIndex + 1); // X and Y are only sent back by browsers that support the // event.offsetX and event.offsetY properties. if(e.XCoordinate != -1) lblClickMsg.Text += String.Format(CultureInfo.CurrentCulture, "<br>At X,Y {0},{1}", e.XCoordinate, e.YCoordinate); // Track the click count in the Tag property to test view state if(imClickMap.Areas[e.AreaIndex].Tag != null) clickCount = (int)imClickMap.Areas[e.AreaIndex].Tag; clickCount++; lblClickMsg.Text += String.Format(CultureInfo.CurrentCulture, "<br>It has been clicked {0} times", clickCount); imClickMap.Areas[e.AreaIndex].Tag = clickCount; } }
/// <summary> /// This event is fired by the image area at the bottom of the left-side /// image map. /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> /// <remarks>The parameters are not used and it does not cause validation /// events to fire. It is used to enable or disable the right-side image /// map.</remarks> protected void imMap_Click(object sender, ImageMapClickEventArgs e) { imClickMap.Enabled = !imClickMap.Enabled; lblClickMsg.Text = String.Empty; lblEnabledMsg.Text = String.Format(CultureInfo.CurrentCulture, "Image map {0}", imClickMap.Enabled ? "enabled" : "disabled"); // Apply a filter to "gray out" the image map and change the tool tip if(!imClickMap.Enabled) { imClickMap.Style.Add("opacity", ".25"); imClickMap.Style.Add("filter", "Alpha(Opacity=25)"); // For older browsers imClickMap.ToolTip = "Disabled"; } else { imClickMap.Style.Remove("opacity"); imClickMap.Style.Remove("filter"); imClickMap.ToolTip = "Click an area to post back"; } }
/// <summary> /// When the "Visit web site" area is double-clicked, open the web page /// </summary> /// <param name="sender">The sender of the event (the image area)</param> /// <param name="e">The event arguments</param> private void VisitWebSite_DoubleClick(object sender, ImageMapClickEventArgs e) { try { System.Diagnostics.Process.Start("https://github.com/EWSoftware/ImageMaps"); } catch(Exception ex) { MessageBox.Show("Unable to start web browser for URL", "URL Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); // Log the exception to the debugger for the developer System.Diagnostics.Debug.Write(ex.ToString()); } }
//===================================================================== /// <summary> /// The image map can handle click events or the areas can handle their own events. In this demo, the /// image map handles the click event for areas 1, 2, 5, and 6. Area 0 has it's own Click handler and /// area 3 only responds to double-clicks with its own DoubleClick handler. /// </summary> /// <param name="sender">The sender of the event (the image map)</param> /// <param name="e">The event arguments</param> private void imMap_Click(object sender, ImageMapClickEventArgs e) { // We'll handle the click for image area 0 (toggle the image map's owner status) switch(imMap.FocusedArea) { case 5: // Show the interactive property demo using(ImageMapPropertyForm dlg = new ImageMapPropertyForm()) { dlg.ShowDialog(); } break; case 6: // Exit the application this.Close(); break; default: if(imMap.FocusedArea != 0 && imMap.FocusedArea != 3) MessageBox.Show(String.Format(CultureInfo.CurrentUICulture, "You clicked area " + "#{0} ({1}) at point {2}, {3}", e.AreaIndex + 1, imMap.Areas[e.AreaIndex].ToolTip, e.XCoordinate, e.YCoordinate), "Image Map Clicked", MessageBoxButtons.OK, MessageBoxIcon.Information); break; } }
/// <summary> /// The click event handler for the owner draw on/off image area /// </summary> /// <param name="sender">The sender of the event (the image area)</param> /// <param name="e">The event arguments</param> private void areaOwnerDrawOnOff_Click(object sender, ImageMapClickEventArgs e) { // Turn owner draw on/off for the image map imMap.OwnerDraw = !imMap.OwnerDraw; // Disable owner drawing of the two areas when the image map is owner drawn. It draws them in that // case. areaOwnerDrawOnOff.OwnerDraw = areaVisitWebSite.OwnerDraw = !imMap.OwnerDraw; }