-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeyInput.xaml.cs
81 lines (67 loc) · 2.5 KB
/
KeyInput.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
using CopyPlusPlus.Properties;
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
namespace CopyPlusPlus
{
/// <summary>
/// Interaction logic for KeyInput.xaml
/// </summary>
public partial class KeyInput : Window
{
//Get MainWindow
private readonly MainWindow _mainWindow = Application.Current.Windows.Cast<Window>().FirstOrDefault(window => window is MainWindow) as MainWindow;
// Holds a value determining if this is the first time the box has been clicked
// So that the text value is not always wiped out.
private bool _hasBeenClicked1;
private bool _hasBeenClicked2;
public KeyInput()
{
InitializeComponent();
TextBox1.Text = Settings.Default.AppID == "None" ? "点击这里输入" : Settings.Default.AppID;
TextBox2.Text = Settings.Default.SecretKey == "None" ? "关闭窗口自动保存" : Settings.Default.SecretKey;
}
private void ClearText(object sender, RoutedEventArgs e)
{
var box = (TextBox)sender;
switch (box.Name)
{
case "TextBox1":
{
if(box.Text != "点击这里输入") return;
if (!_hasBeenClicked1)
{
box.Text = "";
_hasBeenClicked1 = true;
}
break;
}
case "TextBox2":
{
if (box.Text != "关闭窗口自动保存") return;
if (!_hasBeenClicked2)
{
box.Text = "";
_hasBeenClicked2 = true;
}
break;
}
}
}
private void WriteKey(object sender, EventArgs e)
{
if (TextBox1.Text != "点击这里输入" && TextBox1.Text != "" && TextBox1.Text != " ")
{
_mainWindow.TranslateId = TextBox1.Text;
Settings.Default.AppID = TextBox1.Text;
}
if (TextBox2.Text != "关闭窗口自动保存" && TextBox2.Text != "" && TextBox2.Text != " ")
{
_mainWindow.TranslateKey = TextBox2.Text;
Settings.Default.SecretKey = TextBox2.Text;
}
Settings.Default.Save();
}
}
}