SampleReportControl.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #if !DEBUG
  11. [DesignTimeVisible(false)]
  12. #endif
  13. internal class SampleReportControl : Control
  14. {
  15. private Report report;
  16. private float zoom;
  17. private bool fullPagePreview;
  18. [Browsable(false)]
  19. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  20. public Report Report
  21. {
  22. get { return report; }
  23. set
  24. {
  25. report = value;
  26. Refresh();
  27. }
  28. }
  29. [DefaultValue(1f)]
  30. public float Zoom
  31. {
  32. get { return zoom; }
  33. set
  34. {
  35. zoom = value;
  36. Refresh();
  37. }
  38. }
  39. [DefaultValue(false)]
  40. public bool FullPagePreview
  41. {
  42. get { return fullPagePreview; }
  43. set
  44. {
  45. fullPagePreview = value;
  46. Refresh();
  47. }
  48. }
  49. protected override void OnPaint(PaintEventArgs e)
  50. {
  51. base.OnPaint(e);
  52. Graphics g = e.Graphics;
  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. using (Pen p = new Pen(Color.FromArgb(127, 157, 185)))
  70. {
  71. g.DrawRectangle(p, 0, 0, Width - 1, Height - 1);
  72. }
  73. }
  74. public SampleReportControl()
  75. {
  76. zoom = 1;
  77. BackColor = SystemColors.AppWorkspace;
  78. SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true);
  79. }
  80. }
  81. }