Posted By

AndrewVos on 04/16/08


Tagged

draw arrow


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

AndrewVos
umang_nine


Draw an Arrow


 / Published in: C#
 

  1. //Example Usage
  2. Rectangle arrowRectangle = new Rectangle(2, 2, 100,70);
  3. Pen arrowPen = new Pen(Color.Blue);
  4. LinearGradientBrush arrowBrush = new LinearGradientBrush(arrowRectangle, Color.LightBlue, Color.Blue, LinearGradientMode.Vertical);
  5.  
  6. DrawArrow(e.Graphics, arrowPen, arrowBrush, arrowRectangle);
  7.  
  8. public static void DrawArrow(Graphics graphics, Pen pen, Brush brush, Rectangle area) {
  9. graphics.SmoothingMode = SmoothingMode.AntiAlias;
  10.  
  11. float bodyHeight = (area.Height / 3);
  12. float headWidth = (area.Width / 3);
  13. float bodyWidth = area.Width - headWidth;
  14.  
  15. PointF[] points = new PointF[7];
  16.  
  17. points[0] = new PointF(area.Left, area.Top + bodyHeight);
  18. points[1] = new PointF(area.Left + bodyWidth, area.Top + bodyHeight);
  19. points[2] = new PointF(area.Left + bodyWidth, area.Top);
  20. points[3] = new PointF(area.Right, area.Top + (area.Height / 2));
  21. points[4] = new PointF(area.Left + bodyWidth, area.Bottom);
  22. points[5] = new PointF(area.Left + bodyWidth, area.Bottom - bodyHeight);
  23. points[6] = new PointF(area.Left, area.Bottom - bodyHeight);
  24.  
  25. GraphicsPath path = new GraphicsPath();
  26. path.AddPolygon(points);
  27.  
  28. graphics.FillPath(brush, path);
  29. graphics.DrawPath(pen, path);
  30.  
  31. path.Dispose();
  32. // 2
  33. // |\
  34. // | \
  35. //0------1 >3
  36. //6------5 /
  37. // |/
  38. // 4
  39. }

Report this snippet  

You need to login to post a comment.