-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrmMain.cs
More file actions
215 lines (194 loc) · 6.54 KB
/
Copy pathFrmMain.cs
File metadata and controls
215 lines (194 loc) · 6.54 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
using System.Diagnostics;
using System.Security.Policy;
namespace Desktop_Tool
{
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
FilesToList();
Define.isClose = true;
Define.isOpen = false;
Location = new Point(Define.CLOSEVOL_SIZE, 100);
}
private void button1_Click(object sender, EventArgs e)
{
if (Define.isClose)
{
OpenSlowly();
}
else if (Define.isOpen)
{
CloseSlowly();
}
}
private void CloseSlowly()
{
int i = Define.OPENVOL_SIZE;
while (i < Define.CLOSEVOL_SIZE)
{
Thread.Sleep(1);
i += 20;
Location = new Point(i, 100);
}
StateCtrlBtn.Text = "《";
Define.isClose = true;
Define.isOpen = false;
}
private void OpenSlowly()
{
int i = Define.CLOSEVOL_SIZE;
while (i > Define.OPENVOL_SIZE)
{
Thread.Sleep(1);
i -= 20;
Location = new Point(i, 100);
}
StateCtrlBtn.Text = "》";
Define.isOpen = true;
Define.isClose = false;
}
private void listBox1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data == null)
return;
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Move;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void listBox1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data == null) return;
string[] s = (string[])e.Data.GetData(DataFormats.FileDrop);
//CreateDirectoryOrFile("临时");
//托入的文件放入文件夹里
foreach (string s2 in s)
{
if(!Path.HasExtension(s2))
{
return;
}
string fileName = Path.GetFileName(s2);
string dest = "D:\\临时文件\\" + fileName;
MoveFiles(s2, dest);
}
FilesToList();
}
/// <summary>
/// 文件夹映射到listBox中
/// </summary>
private void FilesToList()
{
//将文件夹里的文件路径放到临时变量里
string folderPath = "D:\\临时文件\\";
string[] files = Directory.GetFiles(folderPath, "*.*", SearchOption.AllDirectories);
//在临时变量里查找文件,将没有的加入到临时变量中
foreach (string file in files)
{
if (!Define.Files.ContainsKey(Path.GetFileName(file)))
Define.Files.Add(Path.GetFileName(file), file);
}
//在文件中查找临时变量,将没有的删除
foreach (string file in Define.Files.Values)
{
if (!files.Contains(file))
Define.Files.Remove(Path.GetFileName(file));
}
//绑定数据源
listBox1.DataSource = Define.Files.Keys.ToList<string>();
listBox1.Refresh();
}
private void MoveFiles(string sourceFileName, string destFileName)
{
string path = sourceFileName;
string path2 = destFileName;
try
{
if (!File.Exists(path))
{
using (FileStream fs = File.Create(path)) { }
}
// Ensure that the target does not exist.
if (File.Exists(path2))
File.Delete(path2);
// Move the file.
File.Move(path, path2);
// See if the original exists now.
if (File.Exists(path))
{
Console.WriteLine("The original file still exists, which is unexpected.");
}
else
{
Console.WriteLine("The original file no longer exists, which is expected.");
}
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
}
private void listBox1_DoubleClick(object sender, EventArgs e)
{
if (listBox1.SelectedItems.Count > 0)
{
string? file = listBox1.SelectedItems[0].ToString();
if (file == null) return;
string Excutefile = Define.Files[file].ToString();
var psi = new ProcessStartInfo
{
FileName = Excutefile,
UseShellExecute = true
};
Process.Start(psi);
}
}
private void listBox1_MouseClick(object sender, MouseEventArgs e)
{
if (listBox1.SelectedItems.Count > 0)
{
if (e.Button == MouseButtons.Right)
{
openFileRode.Visible = true;
delete.Visible = true;
}
}
}
private void delete_Click(object sender, EventArgs e)
{
if (listBox1.SelectedItems.Count > 0)
{
string? filePath = listBox1.SelectedItems[0].ToString();
if (filePath == null) return;
File.Delete(Define.Files[filePath].ToString());
FilesToList();
}
}
private void openFileRode_Click(object sender, EventArgs e)
{
if (listBox1.SelectedItems.Count > 0)
{
string? FilesPath = null;
foreach (var items in Define.Files)
{
if (items.Key.Contains(listBox1.SelectedItems[0].ToString()))
{
FilesPath = items.Value.ToString().Replace(items.Key, "");
}
}
var psi = new ProcessStartInfo
{
FileName = FilesPath,
UseShellExecute = true
};
Process.Start(psi);
}
}
}
}