-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReceiptPreviewControl.cs
More file actions
34 lines (30 loc) · 1.48 KB
/
Copy pathReceiptPreviewControl.cs
File metadata and controls
34 lines (30 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System.ComponentModel;
namespace FMPReceiptPrinter;
public sealed class ReceiptPreviewControl : Control
{
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public ReceiptData Receipt { get; set; } = new();
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public ReceiptTemplate Template { get; set; } = new();
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public HashSet<ReceiptSlot> Slots { get; set; } = [ReceiptSlot.TopLeft];
public ReceiptPreviewControl()
{
DoubleBuffered = true;
BackColor = Color.FromArgb(230, 232, 235);
ResizeRedraw = true;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
var available = RectangleF.Inflate(ClientRectangle, -18, -18);
var ratio = ReceiptRenderer.PageWidth / ReceiptRenderer.PageHeight;
var width = Math.Min(available.Width, available.Height * ratio);
var height = width / ratio;
if (height > available.Height) { height = available.Height; width = height * ratio; }
var target = new RectangleF((ClientSize.Width-width)/2f, (ClientSize.Height-height)/2f, width, height);
e.Graphics.FillRectangle(Brushes.White, target);
e.Graphics.DrawRectangle(Pens.Gray, Rectangle.Round(target));
ReceiptRenderer.DrawPage(e.Graphics, target, Receipt, Template, Slots);
}
}