Esempio n. 1
0
        /// <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;
            }
        }
Esempio n. 2
0
        //=====================================================================

        /// <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;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// This raises the image area <see cref="DoubleClick"/> event
        /// </summary>
        /// <param name="e">The event arguments</param>
        protected virtual void OnDoubleClick(ImageMapClickEventArgs e)
        {
            var handler = DoubleClick;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Esempio n. 4
0
        /// <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;
        }
Esempio n. 5
0
        /// <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());
            }
        }
Esempio n. 6
0
        // These are used in the help file examples
        #region Click event examples

        /// <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";
            }
        }
Esempio n. 7
0
 /// <summary>
 /// A simple image area click handler
 /// </summary>
 /// <param name="sender">The sender of the event</param>
 /// <param name="e">The event arguments</param>
 private void imMap_Click(object sender, ImageMapClickEventArgs e)
 {
     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);
 }
Esempio n. 8
0
        /// <summary>
        /// This raises the image map <see cref="Click"/> event
        /// </summary>
        /// <param name="e">The event arguments</param>
        protected virtual void OnClick(ImageMapClickEventArgs e)
        {
            var handler = Click;

            if(handler != null)
                handler(this, e);
        }
Esempio n. 9
0
        /// <summary>
        /// This is called to raise one of the mouse click events.  They are all similar and use the same code.
        /// </summary>
        /// <param name="areaEvent">The image area mouse event to raise</param>
        /// <param name="clickLocation">The mouse cursor click location</param>
        /// <param name="args">The event arguments</param>
        private void RaiseMouseClickEvent(ImageAreaEvent areaEvent, Point clickLocation, object args)
        {
            ImageMapClickEventArgs ce = null;

            Point offset = CalculateImageOffset();

            int nArea = this.ImageAreaAtPoint(new Point(clickLocation.X - offset.X, clickLocation.Y - offset.Y));

            if(nArea != -1)
            {
                ImageAreaBase a = (ImageAreaBase)this.Areas[nArea];

                if(a.Action == AreaClickAction.FireEvent)
                {
                    if(activeArea != nArea)
                        this.Focus(nArea, true);

                    // Create ImageMapClickEventArgs if the passed arguments parameter is null
                    if(args == null)
                        ce = new ImageMapClickEventArgs(nArea, clickLocation.X - offset.X,
                            clickLocation.Y - offset.Y);

                    switch(areaEvent)
                    {
                        case ImageAreaEvent.Click:
                            a.RaiseEvent(areaEvent, ce);
                            this.OnClick(ce);
                            break;

                        case ImageAreaEvent.DoubleClick:
                            a.RaiseEvent(areaEvent, ce);
                            this.OnDoubleClick(ce);
                            break;

                        case ImageAreaEvent.MouseDown:
                        case ImageAreaEvent.MouseUp:
                            a.RaiseEvent(areaEvent, args);
                            break;

                        default:
                            throw new NotImplementedException("Unknown event used for RaiseMouseClickEvent");

                    }
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// This is overridden to handle processing of image area access keys
        /// </summary>
        /// <param name="charCode">The character code</param>
        /// <returns>True if handled, false if not</returns>
        protected override bool ProcessMnemonic(char charCode)
        {
            ImageAreaBase a;
            bool result = false;

            for(int idx = 0; idx < this.Areas.Count; idx++)
            {
                a = (ImageAreaBase)this.Areas[idx];

                if(a.Enabled && a.Action == AreaClickAction.FireEvent && a.AccessKey != null &&
                  a.AccessKey[0] == Char.ToUpper(charCode, CultureInfo.InvariantCulture))
                {
                    result = true;
                    this.Focus(idx, true);

                    ImageMapClickEventArgs ce = new ImageMapClickEventArgs(idx, -1, -1);

                    a.RaiseEvent(ImageAreaEvent.Click, ce);
                    this.OnClick(ce);
                }
            }

            if(!result)
                result = base.ProcessMnemonic(charCode);

            return result;
        }
Esempio n. 11
0
        /// <summary>
        /// This is overridden to fire the image map click event if an image area has the focus and the Space bar
        /// or Enter key is pressed.
        /// </summary>
        /// <param name="charCode">The character code</param>
        /// <returns>True if handled, false if not</returns>
        protected override bool ProcessDialogChar(char charCode)
        {
            if(activeArea != -1 && (charCode == '\r' || charCode == ' '))
            {
                ImageAreaBase a = (ImageAreaBase)this.Areas[activeArea];
                ImageMapClickEventArgs ce = new ImageMapClickEventArgs(activeArea, -1, -1);

                a.RaiseEvent(ImageAreaEvent.Click, ce);
                this.OnClick(ce);
                return true;
            }

            return base.ProcessDialogChar(charCode);
        }