Repository navigation
Expand file tree
/
Copy pathForm1.cs
More file actions
910 lines (786 loc) · 31.2 KB
/
Copy pathForm1.cs
File metadata and controls
910 lines (786 loc) · 31.2 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
using Lightspeed_UI.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Timer = System.Windows.Forms.Timer;
namespace Lightspeed_UI
{
public partial class Form1 : Form
{
private Timer checkMouseTimer; // 定时器检查鼠标位置
private Timer animationTimer; // 用于动画
private bool isHidden = false; // 记录窗口是否隐藏
private bool isAnimating = false; // 记录是否在执行动画
private int hiddenY; // 窗口隐藏时的 Y 坐标
private int visibleY; // 窗口可见时的 Y 坐标
private int animationSpeed = 50; // 每次动画移动的像素
private WebBrowser webBrowser;
Panel buttonPanel;
// 顶部间距
public int tophieght = 56;
private DateTime mouseAtTopTime; // 记录鼠标到达顶部的时间
private bool isWaitingForDelay = false; // 是否正在等待延迟
public Form1()
{
string[] args = Environment.GetCommandLineArgs();
if (args.Contains("--help"))
{
string helpFile = Path.Combine(@"c:\lightspeed", "help.txt");
string helpContent = File.Exists(helpFile) ? File.ReadAllText(helpFile) : "No help info found. Please refresh AHK.";
HelpForm hf = new HelpForm(helpContent);
hf.ShowDialog();
Environment.Exit(0);
}
InitializeComponent();
InitializeUI();
// 添加事件处理程序
this.LocationChanged += Form1_LocationChanged;
// 从设置中加载上次的窗口位置和大小
this.Width = 410;
this.Height = 545 + tophieght;
// 从设置中加载位置,如果有的话
if (Settings.Default.WindowLeft != -1 && Settings.Default.WindowTop != -1)
{
this.Location = new Point(Settings.Default.WindowLeft, Settings.Default.WindowTop);
}
else
{
this.Location = new Point((Screen.PrimaryScreen.WorkingArea.Width - this.Width) / 2, visibleY);
}
visibleY = 0;
hiddenY = -this.Height + 5;
checkMouseTimer = new Timer();
checkMouseTimer.Interval = 100;
checkMouseTimer.Tick += CheckMousePosition;
checkMouseTimer.Start();
animationTimer = new Timer();
animationTimer.Interval = 5; // 10ms 刷新一次动画
animationTimer.Tick += AnimateWindow;
label1.Text = "";
label2.Text = "";
label3.Text = "";
label4.Text = "";
if (Settings.Default.autobutton5)
{
checkbox1.Checked = true;
button4_Click(button4, EventArgs.Empty);
}
if (!Directory.Exists("c:/lightspeed"))
{
OpenSettings(button4, EventArgs.Empty);
label1.Text = "第一次使用,需要建立文件夹 C:/lightspeed,点击左边按钮创建 ";
label1.ForeColor = Color.Red;
}
mouseAtTopTime = DateTime.MinValue;
}
private void CheckMousePosition(object sender, EventArgs e)
{
Point cursorPos = Cursor.Position;
// 使用窗口自身的水平范围作为触发区域
int formLeft = this.Left;
int formRight = this.Left + this.Width;
// 获取当前鼠标所在的屏幕
Screen currentScreen = Screen.FromPoint(cursorPos);
// 检查鼠标是否在窗口的水平范围内且靠近顶部
bool isAtTopEdge = cursorPos.Y <= currentScreen.WorkingArea.Y + 5 &&
cursorPos.X >= formLeft &&
cursorPos.X <= formRight;
bool isOnForm = this.Bounds.Contains(cursorPos);
if (!isHidden && this.Top <= currentScreen.WorkingArea.Y && !isOnForm)
{
hiddenY = currentScreen.WorkingArea.Y - this.Height + 5;
StartAnimation(hiddenY);
this.TopMost = true;
isWaitingForDelay = false;
Cursor.Current = Cursors.Default;
}
else if (isHidden && isAtTopEdge)
{
if (!isWaitingForDelay)
{
mouseAtTopTime = DateTime.Now;
isWaitingForDelay = true;
Cursor.Current = Cursors.WaitCursor;
}
else if ((DateTime.Now - mouseAtTopTime).TotalSeconds >= 0.5)
{
StartAnimation(currentScreen.WorkingArea.Y); // 使用当前屏幕的顶部Y坐标
this.TopMost = false;
isWaitingForDelay = false;
Cursor.Current = Cursors.Default;
}
}
else if (isHidden && isOnForm)
{
StartAnimation(currentScreen.WorkingArea.Y); // 使用当前屏幕的顶部Y坐标
this.TopMost = false;
isWaitingForDelay = false;
Cursor.Current = Cursors.Default;
}
else
{
isWaitingForDelay = false;
Cursor.Current = Cursors.Default;
}
}
private void StartAnimation(int targetY)
{
if (isAnimating) return;
isAnimating = true;
animationTimer.Tag = targetY;
animationTimer.Start();
}
private void AnimateWindow(object sender, EventArgs e)
{
int targetY = (int)animationTimer.Tag;
if (this.Top < targetY)
this.Top = Math.Min(this.Top + animationSpeed, targetY);
else if (this.Top > targetY)
this.Top = Math.Max(this.Top - animationSpeed, targetY);
else
{
animationTimer.Stop();
isAnimating = false;
isHidden = (this.Top == hiddenY);
}
}
private void Form1_Load(object sender, EventArgs e)
{
this.Opacity = Settings.Default.opicity;
UpdateTrayMenu();
}
private void InitializeUI()
{
// 设置窗体的黑色背景
this.BackColor = Color.Black;
// 创建一个 Panel 用于放置按钮,并设置为黑色背景
buttonPanel = new Panel
{
Dock = DockStyle.Left,
Width = 100,
BackColor = Color.FromArgb(30, 30, 30) // 深灰色背景
};
// 添加向上一级按钮
Button backButton = new Button
{
Text = " < ",
Width = 45,
Height = 40,
Top = 10,
Left = 5,
BackColor = Color.FromArgb(45, 45, 45), // 深灰色背景
ForeColor = Color.White // 白色字体
};
backButton.FlatStyle = FlatStyle.Flat; // 扁平样式
backButton.FlatAppearance.BorderColor = Color.FromArgb(64, 64, 64); // 边框颜色
backButton.Click += button6_Click; // 添加按钮点击事件处理程序
buttonPanel.Controls.Add(backButton);
// 添加向下一级级按钮
Button forwardButton = new Button
{
Text = " > ",
Width = 45,
Height = 40,
Top = 10,
Left = 50,
BackColor = Color.FromArgb(45, 45, 45), // 深灰色背景
ForeColor = Color.White // 白色字体
};
forwardButton.FlatStyle = FlatStyle.Flat; // 扁平样式
forwardButton.FlatAppearance.BorderColor = Color.FromArgb(64, 64, 64); // 边框颜色
forwardButton.Click += button7_Click; // 添加按钮点击事件处理程序
buttonPanel.Controls.Add(forwardButton);
// 创建 10 个按钮,并设置为黑色背景和白色字体
for (int i = 0; i <= 9; i++)
{
Button btn = new Button
{
Text = i.ToString(),
Tag = i, // 将按钮的 Tag 设置为数字,用于点击事件中获取
Width = 90,
Height = 40,
Top = i * 45 + tophieght, // 设置按钮的垂直位置
Left = 5,
BackColor = Color.FromArgb(45, 45, 45), // 深灰色背景
ForeColor = Color.White // 白色字体
};
btn.FlatStyle = FlatStyle.Flat; // 扁平样式
btn.FlatAppearance.BorderColor = Color.FromArgb(64, 64, 64); // 边框颜色
btn.Click += Btn_Click; // 添加按钮点击事件处理程序
buttonPanel.Controls.Add(btn);
}
Button btn_last = new Button
{
Text = "settings",
Width = 90,
Height = 40,
Top = 450 + tophieght, // 设置按钮的垂直位置
Left = 5,
BackColor = Color.FromArgb(45, 45, 45), // 深灰色背景
ForeColor = Color.White // 白色字体
};
btn_last.FlatStyle = FlatStyle.Flat; // 扁平样式
btn_last.FlatAppearance.BorderColor = Color.FromArgb(64, 64, 64); // 边框颜色
btn_last.Click += OpenSettings; // 添加按钮点击事件处理程序
buttonPanel.Controls.Add(btn_last);
// 创建 WebBrowser 控件
webBrowser = new WebBrowser
{
Dock = DockStyle.Fill,
ScriptErrorsSuppressed = true, // 抑制 JavaScript 错误弹窗
};
// 将 Panel 和 WebBrowser 控件添加到窗体
this.Controls.Add(webBrowser);
this.Controls.Add(buttonPanel);
// 设置初始页面
webBrowser.Navigate("file://C:/lightspeed/0");
this.PreviewKeyDown += WebBrowserKeyFunction;
webBrowser.PreviewKeyDown += WebBrowserKeyFunction;
}
private void WebBrowserKeyFunction(object sender, PreviewKeyDownEventArgs e)
{
if ((e.Alt == true && e.KeyCode == Keys.Left) )
{
if (webBrowser.CanGoBack)
{
webBrowser.GoBack();
}
}
if ((e.Alt == true && e.KeyCode == Keys.Right))
{
if (webBrowser.CanGoForward)
{
webBrowser.GoForward();
}
}
if ((e.KeyCode == Keys.F5))//按一下 f5刷新 ahk 重启一下
{
MessageBox.Show("lightspeed.ahk 已刷新");
button4_Click(button4, EventArgs.Empty);
}
}
private void Btn_Click(object sender, EventArgs e)
{
webBrowser.Visible = true;
// 获取被点击按钮的 Tag 值
Button clickedButton = sender as Button;
//更新按钮颜色
buttonRefreshColor(clickedButton);
int number = (int)clickedButton.Tag;
// 如果正在开启设置页面,关闭
panel1.Visible = false;
// 更新 WebBrowser 控件的 URI
webBrowser.Navigate($"file://C:/lightspeed/{number}");
}
private void buttonRefreshColor(Button clickedButton)
{
//帮我完成这个函数
//要求 传入的这个btn clickedButton.FlatAppearance.BorderColor = Color.FromArgb(255, 255, 64);
//其他的所有 button FlatAppearance.BorderColor = Color.FromArgb(64, 64, 64);
// 遍历 Panel 中的所有按钮
foreach (Control ctrl in buttonPanel.Controls)
{
// 检查控件是否是按钮
if (ctrl is Button btn)
{
// 如果当前按钮是被点击的按钮,设置边框颜色为黄色
if (btn == clickedButton)
{
btn.FlatAppearance.BorderColor = Color.FromArgb(255, 255, 64); // 设置为黄色
}
else
{
// 否则,设置为灰色边框
btn.FlatAppearance.BorderColor = Color.FromArgb(64, 64, 64); // 设置为灰色
}
}
}
}
private void OpenSettings(object sender, EventArgs e)
{
//var b = new Form2();
//b.Show();
if (!panel1.Visible)
{
//min 460x590
//this.Width = Math.Max(460+120, Width);
this.Height = Math.Max(590, Height);
panel1.Visible = true;
panel1.Top = webBrowser.Top;
panel1.Height = webBrowser.Height;
panel1.Left = webBrowser.Left;
panel1.Width = webBrowser.Width;
webBrowser.Visible = false;
}
else
{
panel1.Visible = false;
webBrowser.Visible = true;
}
}
private void button1_Click(object sender, EventArgs e)
{
string baseFolderPath = @"c:/lightspeed";
if (!Directory.Exists(baseFolderPath))
{
Directory.CreateDirectory(baseFolderPath);
}
for (int i = 0; i < 10; i++)
{
string folderPath = Path.Combine(baseFolderPath, i.ToString());
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
}
label1.Text = ("文件夹检查/创建完成!");
}
private void button2_Click(object sender, EventArgs e)
{
CreateAHK("C:\\lightspeed");
label2.Text = "ahk已生成,C:\\lightspeed\\lightspeed.ahk,包含应用数量:" + LoadFolder2objList("C:\\lightspeed").Count.ToString(); //todo ,懒得优化了,总之这个函数执行了两遍
}
public void CreateAHK(string folderPath)
{
// Define the path to the AHK file
string ahkFilePath = Path.Combine(folderPath, "lightspeed.ahk");
// AHK script content
string ahkContent = @"
#SingleInstance , Force
Menu, Tray, Icon, netshell.dll, 30
#If WinActive(""ahk_exe lightspeed-UI.exe"")
XButton1::Send, {alt down}{Left}{alt up}
XButton2::Send, {alt down}{right}{alt up}
#If WinActive(""ahk_class Shell_TrayWnd"") or WinActive(""ahk_class Shell_SecondaryTrayWnd"") or WinActive(""python lightspeed.py"") or WinActive(""ahk_class WorkerW"") or WinActive(""ahk_class Progman"")
SetTitleMatchMode, 2
ShowAndHideText(text, duration) {
Gui, +LastFound +AlwaysOnTop -Caption +ToolWindow +Disabled
Gui, Color, 000000 ; background black
Gui, Font, s15, Verdana ; fontsize and fontname
textWidth := 400
textHeight := 40
winX := 0
winY := 20
Gui, Add, Text, x%winX% y%winY% w%textWidth% h%textHeight% cFFFFFF Center, %text%
Gui, Show, NA
WinSet, Transparent, 180 ; 0 is fully transparent, 255 is fully opaque
SetTimer, DestroyGui, %duration%
return
DestroyGui:
Gui, Destroy
return
}
open_or_activate(title, path) {
ShowAndHideText(title, 600)
if (WinExist(title)) {
WinActivate, %title%
} else {
Run, ""%path%""
}
}
!0::
open_or_activate(""C:\lightspeed\0"",""C:\lightspeed\0"")
return
!1::
open_or_activate(""C:\lightspeed\1"",""C:\lightspeed\1"")
return
!2::
open_or_activate(""C:\lightspeed\2"",""C:\lightspeed\2"")
return
!3::
open_or_activate(""C:\lightspeed\3"",""C:\lightspeed\3"")
return
!4::
open_or_activate(""C:\lightspeed\4"",""C:\lightspeed\4"")
return
!5::
open_or_activate(""C:\lightspeed\5"",""C:\lightspeed\5"")
return
!6::
open_or_activate(""C:\lightspeed\6"",""C:\lightspeed\6"")
return
!7::
open_or_activate(""C:\lightspeed\7"",""C:\lightspeed\7"")
return
!8::
open_or_activate(""C:\lightspeed\8"",""C:\lightspeed\8"")
return
!9::
open_or_activate(""C:\lightspeed\9"",""C:\lightspeed\9"")
return
";
var lightspeed_obj_list = LoadFolder2objList(folderPath);
// Build help string for AHK
StringBuilder sb = new StringBuilder();
sb.Append("--- Hotkeys ---\\n");
sb.Append("Alt+0~9 : Open Folders\\n");
foreach (var item in lightspeed_obj_list)
{
sb.Append($"{item.HotkeyStr} : {item.Title}\\n");
}
// Use actual AHK backtick n for newlines when writing to the string
string helpStringText = sb.ToString();
File.WriteAllText(Path.Combine(folderPath, "help.txt"), helpStringText);
ahkContent += $@"
!/::
Run, ""{Assembly.GetExecutingAssembly().Location}"" --help
return
" + "\n";
foreach (var item in lightspeed_obj_list)
{
ahkContent += (item.getAhkString());
ahkContent += "\n";
}
// Write the AHK script content to the file
System.IO.File.WriteAllText(ahkFilePath, ahkContent, Encoding.GetEncoding("GBK"));
// Refresh the tray menu context
UpdateTrayMenu();
}
public List<lightspeed_obj> LoadFolder2objList(string folderPath)
{
var lightspeed_obj_list = new List<lightspeed_obj>();
var dubcheckList = new List<string>();
for (int i = 0; i < 10; i++)
{
var tf = folderPath + "\\" + i;
if (!Directory.Exists(tf)) continue;
var entries = Directory.GetFileSystemEntries(tf);
foreach (var file in entries)
{
var hotkey = "";
var title = "";
if (Path.GetFileName(file) == "desktop.ini") continue;
if (Path.GetFileName(file)[0] >= 'A' && Path.GetFileName(file)[0] <= 'Z' || Path.GetFileName(file)[0] >= 'a' && Path.GetFileName(file)[0] <= 'z')
{
hotkey = i + " & " + char.ToLower(Path.GetFileName(file)[0]);
}
else
{
Console.WriteLine($"nope{Path.GetFileName(file)}");
continue;
}
if (Path.GetFileName(file).StartsWith("["))
{
hotkey = i + " & " + char.ToLower(Path.GetFileName(file)[1]);
title = Path.GetFileName(file).Substring(3).Replace(".lnk", "").Replace(" - 快捷方式", "").Replace(" - 副本", "");
}
if (dubcheckList.Contains(hotkey))
{
Console.WriteLine($"{Path.GetFileName(file)} :dublicated key");
continue;
}
dubcheckList.Add(hotkey);
title = System.IO.Path.GetFileNameWithoutExtension(file).Replace(" - 快捷方式", "").Replace(" - 副本", "");
var filepath = Path.Combine(folderPath, file);
lightspeed_obj_list.Add(new lightspeed_obj(title, filepath, hotkey));
}
//MessageBox.Show("Test" + lightspeed_obj_list.Count);
}
return lightspeed_obj_list;
}
public static void StartProgram(string filePath)
{
try
{
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = filePath,
UseShellExecute = true
};
Process.Start(startInfo);
}
catch (Exception e)
{
Console.WriteLine($"Error starting program: {e.Message}");
}
}
private void button3_Click(object sender, EventArgs e)
{
StartProgram("C:\\lightspeed\\lightspeed.ahk");
label3.Text = "执行 lightspeed.ahk";
}
private void button4_Click(object sender, EventArgs e)
{
button2_Click(button4, EventArgs.Empty);
button3_Click(button4, EventArgs.Empty);
label4.Text = "火箭升空";
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string url = "https://kasusa.lanzoul.com/iClHk28thruj";
// 使用默认浏览器打开网页
Process.Start(new ProcessStartInfo
{
FileName = url,
UseShellExecute = true
});
}
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string url = "https://github.com/cornradio/lightspeed/tree/main/seticons";
Process.Start(new ProcessStartInfo
{
FileName = url,
UseShellExecute = true
});
}
private void checkbox1_CheckedChanged(object sender, EventArgs e)
{
Settings.Default.autobutton5 = checkbox1.Checked;
Settings.Default.Save();
}
private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string url = "https://kasusa.lanzoul.com/ix6FC28v6xyf";
Process.Start(new ProcessStartInfo
{
FileName = url,
UseShellExecute = true
});
}
private void labelx_Click(object sender, EventArgs e)
{
}
//back
private void button6_Click(object sender, EventArgs e)
{
if (webBrowser.CanGoBack)
{
webBrowser.GoBack();
webBrowser.Focus();
}
}
//forward
private void button7_Click(object sender, EventArgs e)
{
if (webBrowser.CanGoForward)
{
webBrowser.GoForward();
webBrowser.Focus();
}
}
//big
private void button8_Click(object sender, EventArgs e)
{
this.Width = 850;
}
private void button9_Click(object sender, EventArgs e)
{
this.Width = 450;
}
private void Form1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
}
private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string url = "https://github.com/cornradio/lightspeed-UI";
Process.Start(new ProcessStartInfo
{
FileName = url,
UseShellExecute = true
});
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
this.Opacity = trackBar1.Value/100.00;
label_opacity.Text = trackBar1.Value.ToString();
Settings.Default.opicity = this.Opacity;
Settings.Default.Save();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
e.Cancel = true; // 取消关闭操作
this.Hide(); // 执行 hide 操作
}
}
private void Form1_LocationChanged(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Normal)
{
Settings.Default.WindowLeft = this.Left;
Settings.Default.WindowTop = this.Top;
Settings.Default.Save();
}
}
private void quitToolStripMenuItem_Click(object sender, EventArgs e)
{
Settings.Default.Save();
Application.Exit();
}
private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
// 只处理右键
// 你的右键逻辑,比如弹出菜单
}
if (e.Button == MouseButtons.Left)
{
if (this.Visible)
{
this.Hide();
}
else
{
this.Show();
this.Activate();
}
}
}
private void UpdateTrayMenu()
{
contextMenuStrip1.Items.Clear();
string baseFolderPath = @"c:/lightspeed";
if (Directory.Exists(baseFolderPath))
{
for (int i = 0; i < 10; i++)
{
string folderPath = Path.Combine(baseFolderPath, i.ToString());
if (!Directory.Exists(folderPath)) continue;
var folderItem = new ToolStripMenuItem($"📁 {i}");
folderItem.Tag = folderPath;
folderItem.Click += (s, ev) => {
if (s is ToolStripMenuItem sub && sub.Tag is string fp)
StartProgram(fp);
};
folderItem.DropDownItems.Add(new ToolStripMenuItem("Loading..."));
folderItem.DropDownOpening += (s, ev) => LazyLoadMenu((ToolStripMenuItem)s);
contextMenuStrip1.Items.Add(folderItem);
}
}
if (contextMenuStrip1.Items.Count > 0)
{
contextMenuStrip1.Items.Add(new ToolStripSeparator());
}
contextMenuStrip1.Items.Add(refreashAhkToolStripMenuItem);
contextMenuStrip1.Items.Add(quitToolStripMenuItem);
}
private void LazyLoadMenu(ToolStripMenuItem parentMenu)
{
if (parentMenu.DropDownItems.Count == 1 && parentMenu.DropDownItems[0].Text == "Loading...")
{
parentMenu.DropDownItems.Clear();
string currentPath = parentMenu.Tag as string;
if (string.IsNullOrEmpty(currentPath)) return;
Type shellType = Type.GetTypeFromProgID("WScript.Shell");
dynamic shell = null;
if (shellType != null) {
shell = Activator.CreateInstance(shellType);
}
try
{
var entries = Directory.GetFileSystemEntries(currentPath);
foreach (var file in entries)
{
if (Path.GetFileName(file).Equals("desktop.ini", StringComparison.OrdinalIgnoreCase)) continue;
string title = Path.GetFileNameWithoutExtension(file)
.Replace(" - 快捷方式", "")
.Replace(" - 副本", "");
if (Path.GetFileName(file).StartsWith("["))
{
title = Path.GetFileName(file).Substring(3)
.Replace(".lnk", "")
.Replace(" - 快捷方式", "")
.Replace(" - 副本", "");
}
bool isDir = Directory.Exists(file);
string targetPath = file;
if (!isDir && file.EndsWith(".lnk", StringComparison.OrdinalIgnoreCase))
{
try
{
if (shell != null)
{
var shortcut = shell.CreateShortcut(file);
string resolvedPath = shortcut.TargetPath;
if (Directory.Exists(resolvedPath))
{
isDir = true;
targetPath = resolvedPath;
}
}
}
catch { }
}
if (isDir)
{
var subFolderItem = new ToolStripMenuItem($"📁 {title}");
subFolderItem.Tag = targetPath; // Using the real path for execution
subFolderItem.Click += (s, ev) => {
if (s is ToolStripMenuItem sub && sub.Tag is string fp)
StartProgram(fp);
};
subFolderItem.DropDownItems.Add(new ToolStripMenuItem("Loading..."));
subFolderItem.DropDownOpening += (s, ev) => LazyLoadMenu((ToolStripMenuItem)s);
parentMenu.DropDownItems.Add(subFolderItem);
}
else
{
var subItem = new ToolStripMenuItem(title);
subItem.Tag = file;
subItem.Click += (s, ev) => {
if (s is ToolStripMenuItem sub && sub.Tag is string path)
StartProgram(path);
};
parentMenu.DropDownItems.Add(subItem);
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Error reading folder {currentPath}: {ex.Message}");
}
finally
{
if (shell != null)
{
Marshal.ReleaseComObject(shell);
}
}
if (parentMenu.DropDownItems.Count == 0)
{
parentMenu.DropDownItems.Add(new ToolStripMenuItem("(Empty)"));
}
}
}
private void refreashAhkToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("lightspeed.ahk 已刷新");
button4_Click(button4, EventArgs.Empty);
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
if (checkBox2.Checked)
{
Settings.Default.autohide = true;
Settings.Default.Save();
}
else
{
Settings.Default.autohide = false;
Settings.Default.Save();
}
}
private void Form1_Shown(object sender, EventArgs e)
{
if (Settings.Default.autohide)
{
checkBox2.Checked = true;
this.Hide();
}
}
}
}