/// <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); } } }
/// <summary> /// Handle the leave event for the focus 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_Leave(object sender, EventArgs e) { ImageAreaPolygon a = (ImageAreaPolygon)sender; a.Tag = "Area Lost Focus"; }
/// <summary> /// Handle the enter event for the focus 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_Enter(object sender, EventArgs e) { ImageAreaPolygon a = (ImageAreaPolygon)sender; a.Tag = "Area Got Focus"; }