Extensions.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using FastReport.Table;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Text;
  6. namespace FastReport.Web
  7. {
  8. public static partial class Extensions
  9. {
  10. public static void FindClickedObject<T>(
  11. this Report Report,
  12. string objectName,
  13. int pageN,
  14. float left,
  15. float top,
  16. Action<T, ReportPage, int> action
  17. )
  18. where T : ComponentBase
  19. {
  20. if (Report.PreparedPages == null)
  21. return;
  22. bool found = false;
  23. while (pageN < Report.PreparedPages.Count && !found)
  24. {
  25. ReportPage page = Report.PreparedPages.GetPage(pageN);
  26. if (page != null)
  27. {
  28. ObjectCollection allObjects = page.AllObjects;
  29. var point = new System.Drawing.PointF(left + 1, top + 1);
  30. foreach (Base obj in allObjects)
  31. {
  32. if (obj is ReportComponentBase)
  33. {
  34. ReportComponentBase c = obj as ReportComponentBase;
  35. if (c is TableBase)
  36. {
  37. TableBase table = c as TableBase;
  38. for (int i = 0; i < table.RowCount; i++)
  39. {
  40. for (int j = 0; j < table.ColumnCount; j++)
  41. {
  42. TableCell textcell = table[j, i];
  43. if (textcell.Name == objectName)
  44. {
  45. RectangleF rect = new RectangleF(table.Columns[j].AbsLeft,
  46. table.Rows[i].AbsTop,
  47. textcell.Width,
  48. textcell.Height);
  49. if (rect.Contains(point))
  50. {
  51. action(textcell as T, page, pageN);
  52. found = true;
  53. break;
  54. }
  55. }
  56. }
  57. if (found)
  58. break;
  59. }
  60. }
  61. else if (c is T)
  62. {
  63. if (c.Name == objectName && c.AbsBounds.Contains(point))
  64. {
  65. action(c as T, page, pageN);
  66. found = true;
  67. break;
  68. }
  69. }
  70. if (found)
  71. break;
  72. }
  73. }
  74. page.Dispose();
  75. pageN++;
  76. }
  77. }
  78. }
  79. }
  80. }