EventIndicator.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using FastReport.Utils;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. namespace FastReport.Design.PageDesigners.Page
  8. {
  9. internal class EventIndicator
  10. {
  11. GraphicsPath indicatorPath;
  12. Dictionary<Type, PropertyDescriptorCollection> propertiesCollection;
  13. public bool HaveToDraw(ComponentBase obj)
  14. {
  15. Type type = obj.GetType();
  16. if (!propertiesCollection.ContainsKey(type))
  17. {
  18. PropertyDescriptorCollection props = TypeDescriptor.GetProperties(obj);
  19. PropertyDescriptorCollection properties = new PropertyDescriptorCollection(null);
  20. foreach (PropertyDescriptor prop in props)
  21. {
  22. BrowsableAttribute attr = prop.Attributes[typeof(BrowsableAttribute)] as BrowsableAttribute;
  23. // skip nonbrowsable properties
  24. if (attr != null && attr.Browsable == false) continue;
  25. // check if property is an event
  26. if (prop.Name.EndsWith("Event"))
  27. properties.Add(prop);
  28. }
  29. propertiesCollection[type] = properties;
  30. }
  31. foreach (PropertyDescriptor prop in propertiesCollection[type])
  32. {
  33. string value = prop.GetValue(obj) as string;
  34. if (value != null && value != "")
  35. return true;
  36. }
  37. return false;
  38. }
  39. public void DrawIndicator(ComponentBase obj, FRPaintEventArgs paintArgs)
  40. {
  41. IGraphics g = paintArgs.Graphics;
  42. IGraphicsState state = g.Save();
  43. g.TranslateTransform(obj.AbsLeft * paintArgs.ScaleX, obj.AbsTop * paintArgs.ScaleY);
  44. g.ScaleTransform(paintArgs.ScaleX, paintArgs.ScaleY);
  45. g.FillPath(Brushes.Red, indicatorPath);
  46. g.Restore(state);
  47. }
  48. public EventIndicator()
  49. {
  50. propertiesCollection = new Dictionary<Type, PropertyDescriptorCollection>();
  51. indicatorPath = new GraphicsPath();
  52. indicatorPath.StartFigure();
  53. indicatorPath.AddPolygon(new PointF[] { new PointF(3, 3), new PointF(10, 8), new PointF(3, 13) });
  54. indicatorPath.CloseFigure();
  55. }
  56. }
  57. }