-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrmMain.cs
More file actions
246 lines (207 loc) · 7.26 KB
/
Copy pathFrmMain.cs
File metadata and controls
246 lines (207 loc) · 7.26 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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
using Microsoft.Win32;
using System.Data;
namespace WallPaper
{
public partial class FrmMain : Form
{
public static int Sindex;
public static string? PNGfile;
public static bool isFollowTime = false;
public static Event evn;
public FrmMain()
{
Sindex = 0;
InitializeComponent();
txtPath.Text = @"C:\Wallpapers";
SetStartup();
Program.GetWallPapers();
evn = new Event();
//evn.Temp= 0;
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
timer.Interval = 1000;
timer.Tick += Timer_Tick1;
timer.Start();
Program.ChangeWallpaper(evn.Temp);
evn.OntempChange += new Event.tempChange(ven_OntempChange);
}
private void ven_OntempChange(object sender, EventArgs e)
{
}
private void Timer_Tick1(object? sender, EventArgs e)
{
DateTime now = DateTime.Now;
TextTimeLabel.Text = now.ToString();
MorningBgn.Value = NightEnd.Value;
NoonBgn.Value = MorningEnd.Value;
AfternoonBgn.Value = NoonEnd.Value;
NightBgn.Value = AfternoonEnd.Value;
if (now.Hour > MorningBgn.Value.Hour && now.Hour <= MorningEnd.Value.Hour)
{
//上午
//index = 0;
evn.Temp = 0;
}
else if (now.Hour > NoonBgn.Value.Hour && now.Hour <= NoonEnd.Value.Hour)
{
//中午
//index = 1;
evn.Temp = 1;
}
else if (now.Hour > AfternoonBgn.Value.Hour && now.Hour <= AfternoonEnd.Value.Hour)
{
//日落
//index = 2;
evn.Temp = 2;
}
else if (now.Hour > NightBgn.Value.Hour)
{
//夜晚
//index = 3;
evn.Temp = 3;
}
label2.Text = @"当前壁纸编号:" + evn.Temp.ToString();
}
private void button1_Click_1(object sender, EventArgs e)
{
//Program.ChangeWallpaper(Sindex);
}
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
Hide();
}
private void button2_Click(object sender, EventArgs e)
{
folderBrowserDialog.Description = "请选择文件夹";
folderBrowserDialog.RootFolder = Environment.SpecialFolder.MyComputer;
folderBrowserDialog.ShowNewFolderButton = true;
if (txtPath.Text.Length > 0) folderBrowserDialog.SelectedPath = txtPath.Text;
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
{
txtPath.Text = folderBrowserDialog.SelectedPath;
}
PNGfile = txtPath.Text;
}
private void button3_Click(object sender, EventArgs e)
{
Program.GetWallPapers();
MessageBox.Show("已获取壁纸!");
}
private void button4_Click(object sender, EventArgs e)
{
MessageBox.Show("先选择你放置的文件路径(四张风景图)[一定要确认路径是正确的!!!],然后点击确定。可以自定义设置时间范围。");
}
private void FrmMain_SizeChanged(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
Hide();
notifyIcon1.Visible = true;
}
}
private void exitMenuItem_Click(object sender, EventArgs e)
{
if (MessageBox.Show("你确定要退出程序吗?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK)
{
notifyIcon1.Visible = false;
Close();
Dispose();
Application.Exit();
}
}
private void hideMenuItem_Click(object sender, EventArgs e)
{
Hide();
}
private void showMenuItem_Click(object sender, EventArgs e)
{
Show();
WindowState = FormWindowState.Normal;
Activate();
}
private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Normal)
{
WindowState = FormWindowState.Minimized;
Hide();
}
else if (WindowState == FormWindowState.Minimized)
{
Show();
WindowState = FormWindowState.Normal;
Activate();
}
}
//设置开机自启动
private void SetStartup()
{
string exePath = Application.ExecutablePath;
string appName = Path.GetFileNameWithoutExtension(exePath);
RegistryKey rk = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
rk?.SetValue(appName, exePath);
}
//移除开机自启动
private void RemoveStartup()
{
string appName = Path.GetFileNameWithoutExtension(Application.ExecutablePath);
RegistryKey rk = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
rk?.DeleteValue(appName, false);
}
private void FrmMain_Load(object sender, EventArgs e)
{
}
#region keyPress
private void MorningBgn_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = true;
}
private void MorningEnd_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = true;
}
private void NoonBgn_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = true;
}
private void NoonEnd_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = true;
}
private void NightEnd_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = true;
}
private void AfternoonEnd_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = true;
}
#endregion
private void label8_Click(object sender, EventArgs e)
{
}
}
public class Event
{
public delegate void tempChange(object sender, EventArgs e);
public event tempChange? OntempChange;
public static int temp = 0;
public int Temp
{
get
{
return temp;
}
set
{
if (temp != value)
{
OntempChange(this, new EventArgs());
int i = value;
Program.ChangeWallpaper(i);
}
temp = value;
}
}
}
}