-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrm_Main.cs
128 lines (107 loc) · 4.04 KB
/
frm_Main.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using QRCoder;
using System;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using WK.Libraries.SharpClipboardNS;
using static QRCoder.QRCodeGenerator;
namespace WinQuickQR
{
public partial class frm_Main : Form
{
private QRCodeGenerator qrGenerator = new QRCodeGenerator();
private SharpClipboard clipboard = new SharpClipboard();
private Regex urlRegex = new Regex(@"^(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?$");
public frm_Main()
{
InitializeComponent();
}
private Image GetQRCode(string input)
{
ECCLevel eccLevel = (ECCLevel)Properties.Settings.Default.ECCLevel;
QRCodeData qrCodeData = qrGenerator.CreateQrCode(input, eccLevel);
QRCode qRCode = new QRCode(qrCodeData);
return qRCode.GetGraphic(Properties.Settings.Default.PixelPerModule);
}
private void Clipboard_ClipboardChanged(object sender, SharpClipboard.ClipboardChangedEventArgs e)
{
if (e.ContentType == SharpClipboard.ContentTypes.Text)
{
string content = e.Content.ToString();
if (!string.IsNullOrEmpty(content))
{
txt_Input.Text = content;
if (!this.Visible)
{
if (Properties.Settings.Default.ShowQuickQRForURL && urlRegex.IsMatch(content))
{
frm_QuickQR quickQR = new frm_QuickQR(this, GetQRCode(content));
quickQR.Show();
}
}
}
}
}
private void txt_Input_TextChanged(object sender, EventArgs e)
{
pb_QR.Image = GetQRCode(txt_Input.Text);
}
private void frm_Main_Load(object sender, EventArgs e)
{
try
{
if (Clipboard.ContainsText())
{
string clipboardText = Clipboard.GetText();
if (!string.IsNullOrEmpty(clipboardText))
{
txt_Input.Text = clipboardText;
}
}
}
catch (Exception ex)
{
Console.Error.WriteLine($"Failed to get clipboard text: {ex.Message}");
}
clipboard.MonitorClipboard = Properties.Settings.Default.MonitorClipboard;
clipboard.ClipboardChanged += Clipboard_ClipboardChanged;
}
private void frm_Main_FormClosing(object sender, FormClosingEventArgs e)
{
if (Properties.Settings.Default.CloseToSystemTray && e.CloseReason == CloseReason.UserClosing)
{
e.Cancel = true;
this.Hide();
}
}
private void btn_SaveToFile_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "PNG Image|*.png";
saveFileDialog.Title = "Save QR Code to File";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
pb_QR.Image.Save(saveFileDialog.FileName);
}
}
private void btn_CopyToClipboard_Click(object sender, EventArgs e)
{
Clipboard.SetImage(pb_QR.Image);
MessageBox.Show("QR Code copied to clipboard.", "WinQuickQR", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void ni_MainIcon_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.WindowState = FormWindowState.Normal;
this.Show();
}
private void mi_NotificationMenu_Open_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Normal;
this.Show();
}
private void mi_NotificationMenu_Exit_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}