12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Windows.Forms;
- using System.ComponentModel;
- using System.Drawing;
- using FastReport.Utils;
- namespace FastReport.Controls
- {
- internal class SampleReportControl : Control
- {
- private Report report;
- private float zoom;
- private bool fullPagePreview;
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public Report Report
- {
- get { return report; }
- set
- {
- report = value;
- Refresh();
- }
- }
- [DefaultValue(1f)]
- public float Zoom
- {
- get { return zoom; }
- set
- {
- zoom = value;
- Refresh();
- }
- }
- [DefaultValue(false)]
- public bool FullPagePreview
- {
- get { return fullPagePreview; }
- set
- {
- fullPagePreview = value;
- Refresh();
- }
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- base.OnPaint(e);
- Graphics g = e.Graphics;
- #if AVALONIA
- g.FontScale = 1;
- #endif
- if (report != null && report.Pages.Count > 0 && report.Pages[0] is ReportPage)
- {
- ReportPage page = report.Pages[0] as ReportPage;
- float zoom = this.zoom;
- if (FullPagePreview)
- {
- float pageWidth = page.WidthInPixels;
- float pageHeight = page.HeightInPixels;
- zoom = Math.Min((Width - 20) / pageWidth, (Height - 20) / pageHeight);
- }
- FRPaintEventArgs args = new FRPaintEventArgs(g, zoom, zoom, report.GraphicCache);
- g.TranslateTransform(10, 10);
- page.Draw(args);
- g.TranslateTransform(-10, -10);
- }
- // draw control frame
- this.DrawVisualStyleBorder(g, new Rectangle(0, 0, Width - 1, Height - 1));
- }
- public SampleReportControl()
- {
- zoom = 1;
- BackColor = SystemColors.AppWorkspace;
- SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true);
- }
- }
- }
|