-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
92 lines (83 loc) · 2.91 KB
/
MainWindow.xaml.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
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;
using System.Drawing;
using System.IO;
namespace ClipBR
{
/// <summary>
///
/// </summary>
public partial class MainWindow : Window
{
string? prevText = null;
DispatcherTimer timer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(1)
};
public MainWindow()
{
InitializeComponent();
}
private void BtnClose_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
private void DragWindow(object sender, MouseButtonEventArgs e)
{
DragMove();
}
private void ClipboardMonitor(object sender, EventArgs e)
{
if (RecordBtn.IsChecked == true)
{
if (Clipboard.ContainsText() == true && Clipboard.GetText() != "Image")
{
NotImage.Opacity = 1;
Image.Opacity = 0;
if (prevText == null && Clipboard.GetText().Contains(KeyWord.Text) || prevText != Clipboard.GetText() && Clipboard.GetText().Contains(KeyWord.Text))
{
NotImage.Text = Clipboard.GetText();
using (StreamWriter writer = new StreamWriter("./History.txt", true))
{
writer.WriteLine(Clipboard.GetText());
prevText = Clipboard.GetText();
writer.Close();
}
}
}
if (Clipboard.ContainsImage() == true)
{
NotImage.Opacity = 0;
Image.Opacity = 1;
Image.Source = Clipboard.GetImage();
string CurrentTime = DateTime.Now.ToString("dd MMMM yyyy HH-mm-ss");
if (Directory.Exists("./Images"))
{
System.Windows.Forms.Clipboard.GetImage().Save("./Images/" + CurrentTime + ".png");
} else
{
Directory.CreateDirectory("./Images");
System.Windows.Forms.Clipboard.GetImage().Save("./Images/" + CurrentTime + ".png");
}
Clipboard.SetText("Image");
}
}
}
private void PinButton_Click(object sender, RoutedEventArgs e)
{
this.Topmost = !Topmost;
}
private void RecordBtn_Checked(object sender, RoutedEventArgs e)
{
timer.Tick += ClipboardMonitor;
timer.Start();
}
private void RecordBtn_Unchecked(object sender, RoutedEventArgs e)
{
timer.Stop();
}
}
}