DrawImageEventArgs Class

This is a custom event arguments class for the DrawImage event.

Definition

Namespace: EWSoftware.ImageMaps.Windows.Forms
Assembly: EWSoftware.ImageMaps.Windows.Forms (in EWSoftware.ImageMaps.Windows.Forms.dll) Version: 2023.1.3.0
public class DrawImageEventArgs : EventArgs
Inheritance
Object    EventArgs    DrawImageEventArgs

Remarks

The event contains the graphics context, the drawing state of the item, an offset if the image is scrolled or centered, and a flag that can be use to indicate whether or not the base class should draw the default focus frame around the active image area.

Example

This is an example of an owner drawn image area event handler. For some other examples, see the demo application. As shown, the image area event properties are not accessible in the designer so you must write code to connect the event handlers. For example, add the code in the form's constructor after the call to InitializeComponent.
C#
public ImageMapEventsForm()
{
    InitializeComponent();

    // Hook up the event handlers.  Since they are not accessible in the
    // designer, we must do it manually.
    ImageAreaBase a = (ImageAreaBase)imMap.Areas[4];
    a.DrawImage += Button_DrawImage;

    a = (ImageAreaBase)imMap.Areas[5];
    a.DrawImage += Button_DrawImage;

    a = (ImageAreaBase)imMap.Areas[6];
    a.DrawImage += Button_DrawImage;

    .
    .
    .
}


/// <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(r.X, 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);
        }
    }
}

Constructors

Properties

DrawFocus This property is used to get or set whether the image map should draw the default focus frame around the active image area.
DrawState This property is used to get or set the state of the item to draw
Graphics This read-only property is used to get the graphics context for drawing
ImageOffset This read-only property is used to get the image offset

Methods

EqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
GetHashCodeServes as the default hash function.
(Inherited from Object)
GetTypeGets the Type of the current instance.
(Inherited from Object)
MemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
ToStringReturns a string that represents the current object.
(Inherited from Object)

See Also