SampleReportControl.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Windows.Forms;
  5. using System.ComponentModel;
  6. using System.Drawing;
  7. using FastReport.Utils;
  8. namespace FastReport.Controls
  9. {
  10. internal class SampleReportControl : Control
  11. {
  12. private Report report;
  13. private float zoom;
  14. private bool fullPagePreview;
  15. [Browsable(false)]
  16. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  17. public Report Report
  18. {
  19. get { return report; }
  20. set
  21. {
  22. report = value;
  23. Refresh();
  24. }
  25. }
  26. [DefaultValue(1f)]
  27. public float Zoom
  28. {
  29. get { return zoom; }
  30. set
  31. {
  32. zoom = value;
  33. Refresh();
  34. }
  35. }
  36. [DefaultValue(false)]
  37. public bool FullPagePreview
  38. {
  39. get { return fullPagePreview; }
  40. set
  41. {
  42. fullPagePreview = value;
  43. Refresh();
  44. }
  45. }
  46. protected override void OnPaint(PaintEventArgs e)
  47. {
  48. base.OnPaint(e);
  49. Graphics g = e.Graphics;
  50. #if AVALONIA
  51. g.FontScale = 1;
  52. #endif
  53. if (report != null && report.Pages.Count > 0 && report.Pages[0] is ReportPage)
  54. {
  55. ReportPage page = report.Pages[0] as ReportPage;
  56. float zoom = this.zoom;
  57. if (FullPagePreview)
  58. {
  59. float pageWidth = page.WidthInPixels;
  60. float pageHeight = page.HeightInPixels;
  61. zoom = Math.Min((Width - 20) / pageWidth, (Height - 20) / pageHeight);
  62. }
  63. FRPaintEventArgs args = new FRPaintEventArgs(g, zoom, zoom, report.GraphicCache);
  64. g.TranslateTransform(10, 10);
  65. page.Draw(args);
  66. g.TranslateTransform(-10, -10);
  67. }
  68. // draw control frame
  69. this.DrawVisualStyleBorder(g, new Rectangle(0, 0, Width - 1, Height - 1));
  70. }
  71. public SampleReportControl()
  72. {
  73. zoom = 1;
  74. BackColor = SystemColors.AppWorkspace;
  75. SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true);
  76. }
  77. }
  78. }