/// <summary> /// Draw the mouse events image area /// </summary> /// <param name="sender">The sender of the event (the image area)</param> /// <param name="e">The event arguments</param> private void MouseArea_DrawImage(object sender, DrawImageEventArgs e) { Graphics g = e.Graphics; ImageAreaCircle a = (ImageAreaCircle)sender; int nShineOffset = a.Radius / 2; Rectangle r = new Rectangle(a.CenterPoint.X - a.Radius, a.CenterPoint.Y - a.Radius, a.Radius * 2, a.Radius * 2); r.Inflate(-2, -2); // Offset the area rectangle by the draw event offset r.Offset(e.ImageOffset.X, e.ImageOffset.Y); using (GraphicsPath pth = new GraphicsPath()) { pth.AddEllipse(r); using (PathGradientBrush pgb = new PathGradientBrush(pth)) { pgb.CenterColor = Color.White; pgb.SurroundColors = new Color [] { Color.BurlyWood }; Point shine = new Point(a.CenterPoint.X - nShineOffset, a.CenterPoint.Y - nShineOffset); shine.Offset(e.ImageOffset.X, e.ImageOffset.Y); pgb.CenterPoint = shine; g.FillEllipse(pgb, r); g.DrawString((string)a.Tag, buttonFont, Brushes.Black, r, sfFormat); } } // We'll let the image map draw the focus frame when needed e.DrawFocus = true; }
/// <summary> /// Draw the "Owner Draw" toggle image area /// </summary> /// <param name="sender">The sender of the event (the image map or image area in this demo)</param> /// <param name="e">The event arguments</param> private void OwnerDrawOnOff_DrawImage(object sender, DrawImageEventArgs e) { Rectangle r = areaOwnerDrawOnOff.Rectangle; r.Inflate(-2, -2); // Offset the area rectangle by the draw event offset r.Offset(e.ImageOffset.X, e.ImageOffset.Y); if (sender is ImageMap) { ControlPaint.DrawCheckBox(e.Graphics, r.X + 5, r.Y, r.Height, r.Height, ButtonState.Checked); r.X += 5 + r.Height; r.Width -= 5 + r.Height; // Use the image map's font e.Graphics.DrawString("&Image map owner draw ON", imMap.Font, Brushes.Black, r, sfFormat); } else { ControlPaint.DrawCheckBox(e.Graphics, r.X + 5, r.Y, r.Height, r.Height, ButtonState.Normal); r.X += 5 + r.Height; r.Width -= 5 + r.Height; e.Graphics.DrawString("&Image map owner draw OFF", imMap.Font, Brushes.Black, r, sfFormat); // Tell the image map to draw the focus rectangle if this is the focused area. It's false by // default if the area is drawing itself. e.DrawFocus = true; } }
// This is used in the help file #region Owner drawn image map help example /// <summary> /// When the image map is owner drawn, you can draw just the background /// or you can draw the image areas too. /// </summary> /// <param name="sender">The sender of the event (the image map)</param> /// <param name="e">The event arguments</param> private void imMap_DrawImage(object sender, DrawImageEventArgs e) { // For this demo, we'll just draw a gradient fill background. // You could get the image using the ImageMap.Image property too. // Offset the drawing rectangle by the image offset in the event // arguments. This indicates the true position of the image when // centered or scrolled. Rectangle r = new Rectangle(e.ImageOffset.X, e.ImageOffset.Y, imMap.ImageMapWidth, imMap.ImageMapHeight); using (LinearGradientBrush lgBrush = new LinearGradientBrush(r, Color.White, Color.SteelBlue, LinearGradientMode.ForwardDiagonal)) { e.Graphics.FillRectangle(lgBrush, r); } e.Graphics.DrawString("All items seen on this form are drawn by " + "the image map or image area DrawImage event handlers. " + "Even with owner draw disabled for the image map, image " + "areas can still be set to owner drawn.", imMap.Font, Brushes.Black, new Rectangle(r.X + 250, r.Y + 10, 325, 100), sfFormat); // The image map can draw areas too. In this case, we defer to // the event handlers as they'll take over if owner drawing of the // image map is turned off. this.OwnerDrawOnOff_DrawImage(sender, e); this.VisitWebSite_DrawImage(sender, e); }
/// <summary> /// Draw the "Visit web site" image area /// </summary> /// <param name="sender">The sender of the event (the image map or image area in this demo)</param> /// <param name="e">The event arguments</param> private void VisitWebSite_DrawImage(object sender, DrawImageEventArgs e) { Font f = imMap.Font; // Use image map font if not focused ImageMap m = (sender as ImageMap); if (m != null) { // If this area is focused or contains the mouse, underline the hyperlink text if (m.FocusedArea == 3 || m.MouseArea == 3) { f = hyperlinkFont; // Tell the image map not to draw the focus. It's true by default in the image map's owner // draw event. if (m.FocusedArea == 3) { e.DrawFocus = false; } } } else { // If the image area is drawing itself, use the event arguments to determine the draw state. If // hot lighting or focused, use the underlined font. if (e.DrawState == DrawState.HotLight || e.DrawState == DrawState.Focus) { f = hyperlinkFont; } } Rectangle r = areaVisitWebSite.Rectangle; // Offset the area rectangle by the draw event offset r.Offset(e.ImageOffset.X, e.ImageOffset.Y); e.Graphics.DrawString("https://github.com/EWSoftware/ImageMaps", f, Brushes.Blue, r, sfFormat); r.Width = (int)e.Graphics.MeasureString("Double-click to go to ", imMap.Font).Width + 4; r.X = r.X - r.Width + 10; e.Graphics.DrawString("&Double-click to go to ", imMap.Font, Brushes.Black, r, sfFormat); }
/// <summary> /// Draw the focus enter/leave image area /// </summary> /// <param name="sender">The sender of the event (the image area)</param> /// <param name="e">The event arguments</param> private void FocusArea_DrawImage(object sender, DrawImageEventArgs e) { Graphics g = e.Graphics; ImageAreaPolygon a = (ImageAreaPolygon)sender; Rectangle r = a.BoundingRectangle; // Offset the area rectangle by the draw event offset r.Offset(e.ImageOffset.X, e.ImageOffset.Y); Point[] pts = new Point[a.Points.Count]; a.Points.CopyTo(pts, 0); using (PathGradientBrush pgb = new PathGradientBrush(pts)) { // Translate the brush coordinates to account for the offset using (Matrix m = new Matrix()) { m.Translate((float)e.ImageOffset.X, (float)e.ImageOffset.Y); pgb.Transform = m; if (e.DrawState == DrawState.Focus) { pgb.SurroundColors = new Color[] { Color.DarkOrange } } ; else { pgb.SurroundColors = new Color[] { Color.Navy } }; pgb.CenterColor = Color.Gray; g.FillRectangle(pgb, r); r.Y += 20; g.DrawString((string)a.Tag, buttonFont, Brushes.Yellow, r, sfFormat); } } }
// This is used in the help file #region Owner drawn area help example /// <summary> /// Draw the "button" image areas /// </summary> /// <param name="sender">The sender of the event (the image area)</param> /// <param name="e">The event arguments</param> private void Button_DrawImage(object sender, DrawImageEventArgs e) { ImageAttributes ia; Graphics g = e.Graphics; // All are ellipse image areas ImageAreaEllipse a = (ImageAreaEllipse)sender; Rectangle r = a.Ellipse; // Offset the area rectangle by the draw event offset r.Offset(e.ImageOffset.X, e.ImageOffset.Y); if (!a.Enabled) { ia = iaDisabled; } else { ia = iaNormal; } using (TextureBrush tb = new TextureBrush(imgFiller, new Rectangle(0, 0, imgFiller.Width, imgFiller.Height), ia)) { tb.WrapMode = WrapMode.Tile; // Translate the brush coordinates to account for the offset using (Matrix m = new Matrix()) { m.Translate((float)r.X, (float)r.Y); tb.Transform = m; // If the area is focused or hot lighted, give it a glow effect if (e.DrawState == DrawState.Focus || e.DrawState == DrawState.HotLight) { using (GraphicsPath pth = new GraphicsPath()) { pth.AddEllipse(r); using (PathGradientBrush pgb = new PathGradientBrush(pth)) { pgb.CenterColor = Color.LightSteelBlue; if (e.DrawState == DrawState.Focus) { pgb.SurroundColors = new Color[] { Color.Yellow } } ; else { pgb.SurroundColors = new Color[] { Color.Blue } }; pgb.FocusScales = new PointF(0.8f, 0.8f); g.FillEllipse(pgb, r); } } } // Draw the filler g.FillEllipse(tb, r); g.DrawString((string)a.Tag, buttonFont, Brushes.Black, r, sfFormat); } } }