/// <summary> /// This is used to fire an event on the image area /// </summary> /// <param name="areaEvent">The event to fire</param> /// <param name="args">The event arguments</param> public void RaiseEvent(ImageAreaEvent areaEvent, object args) { // DrawImage always fires. The image map sets all of the necessary event argument parameters. if (areaEvent == ImageAreaEvent.DrawImage) { OnDrawImage((DrawImageEventArgs)args); return; } // No other events are fired if disabled if (enabled) { switch (areaEvent) { case ImageAreaEvent.Click: this.OnClick((ImageMapClickEventArgs)args); break; case ImageAreaEvent.DoubleClick: this.OnDoubleClick((ImageMapClickEventArgs)args); break; case ImageAreaEvent.MouseDown: this.OnMouseDown((MouseEventArgs)args); break; case ImageAreaEvent.MouseUp: this.OnMouseUp((MouseEventArgs)args); break; case ImageAreaEvent.MouseEnter: this.OnMouseEnter((EventArgs)args); break; case ImageAreaEvent.MouseLeave: this.OnMouseLeave((EventArgs)args); break; case ImageAreaEvent.MouseHover: this.OnMouseHover((EventArgs)args); break; case ImageAreaEvent.MouseMove: this.OnMouseMove((MouseEventArgs)args); break; case ImageAreaEvent.Enter: this.OnEnter((EventArgs)args); break; case ImageAreaEvent.Leave: this.OnLeave((EventArgs)args); break; } } }
/// <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"); } } } }