forked from stevencohn/OneMore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnapshotForm.cs
100 lines (78 loc) · 2.23 KB
/
SnapshotForm.cs
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//************************************************************************************************
// Copyright © 2022 Steven M. Cohn. All Rights Reserved.
//************************************************************************************************
namespace OneMoreCalendar
{
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Forms;
/// <summary>
/// Present a popup window showing a snapshot of a page
/// </summary>
internal partial class SnapshotForm : RoundedForm
{
/// <summary>
/// Consumers should call SnapshotForm(string)
/// </summary>
public SnapshotForm()
: base()
{
InitializeComponent();
StaticColors = true;
}
/// <summary>
/// Initialize the form
/// </summary>
/// <param name="path">Path of the .emf file to display</param>
public SnapshotForm(CalendarPage page, string path)
: this()
{
Path = path;
pathLabel.Text = page.Path;
}
public string Path { get; private set; }
/// <summary>
/// Preload the years to display
/// </summary>
/// <param name="e"></param>
protected override void OnLoad(EventArgs e)
{
// call RoundForm.base to draw background
base.OnLoad(e);
if (!DesignMode && File.Exists(Path))
{
using var source = new Metafile(Path);
var target = new Bitmap(pictureBox.Width, pictureBox.Height);
using var g = Graphics.FromImage(target);
// resize the image 150%
g.DrawImage(source,
new Rectangle(0, 0, (int)(target.Width * 1.5), (int)(target.Height * 1.5)),
new Rectangle(0, 0, source.Width, source.Height),
GraphicsUnit.Pixel
);
//var path = System.IO.Path.Combine(
// System.IO.Path.GetTempPath(),
// System.IO.Path.GetRandomFileName() + ".png");
//target.Save(path, ImageFormat.Png);
//pictureBox.ImageLocation = path;
pictureBox.Image = target;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Handlers...
private void EscapeForm(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
JustLeave(sender, e);
}
}
private void JustLeave(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}