在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → C# 仿搜狗/360 快捷搜索栏 源码下载(实现了开机启动/手动截图/快捷方式/快捷键等)

C# 仿搜狗/360 快捷搜索栏 源码下载(实现了开机启动/手动截图/快捷方式/快捷键等)

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:1.46M
  • 下载次数:53
  • 浏览次数:638
  • 发布时间:2016-02-05
  • 实例类别:C#语言基础
  • 发 布 人:crazycode
  • 文件格式:.zip
  • 所需积分:2
 相关标签: 截图 C# 快捷方式

实例介绍

【实例简介】一套不错的 可供学习的源码

部分用户提示 签名失败时:右键项目>>签名>>ClickOnce中 点击“创建测试证书”即可正常使用

【实例截图】

任务栏 托盘处的功能截图如下:


快速搜索功能如下:





手动截图相关





【核心代码】

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
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
public partial class MainForm : Form
 {
     #region 系统定义
     //private Socket udpCommClient;//命令字socket client
     //private Socket udpMsgClient;//文本消息socket client
     //private Socket udpFileClient;//文件传输socket client
     private Socket udpCommServer;//命令字socket server
     private Socket udpMsgServer;//文本消息socket server
     private Socket udpFileServer;//文件传输 socket server
 
     public List<FormBrowser> listFormBrowser = new List<FormBrowser>();
     private FormBrowser fb = new FormBrowser("",EnumSearchEngine.END_NULL);//浏览器控件
     private FormHelp fh = null;//帮助窗口
     private FormBrowserContainer fbc = new FormBrowserContainer();//浏览器窗口容器
     private FormEyeGuard feyeGuard = new FormEyeGuard();//护眼模式设置
 
     private Point WebFormStartPosition = new Point();
     private Point MainFormStartPosition = new Point();
 
     private string exeName = null;//程序的进程名
     private bool flagFormDocked = false;//是否靠边
     private bool flagFormShow = true;//是否显示
     private bool flagFormExpand = false;//是否展开搜索引擎选择
     private bool flagGlobalHotKeySet = false;//全局快捷键是否注册成功
     private bool flagEyeGuardOpen = false;//护眼模式开启标志
      
 
     private const int WIN_S = 100;//
     private const int CTL_ALT_A = 101;//截屏
     private const int CTL_ALT_SHIFT_X = 102;//关机
     private const int CTL_ALT_SHIFT_S = 103;//休眠
     private const int CTL_ALT_SHIFT_R = 104;//重启
     private const int WIN_F12 = 105;//老板键
     private const int MAIN_FORM_DOCK_X = -545;
     private const int PORT_COMM = 3520;
     private const int PORT_MSG = PORT_COMM   1;
     private const int PORT_FILE = PORT_COMM   2;
     private const string DISPLAY_NAME = "桌面在线";
 
     private Size FB_Normal_Size = new Size(1000, 434);
     private EnumSearchEngine enumCurrentSE = new EnumSearchEngine();//当前的搜索引擎,自动记忆上次使用的习惯,改变搜索按钮的行为
     //private FileStream fswUserInput=null;//用户输入文件流,写模式
     //private FileStream fsrUserInput = null;//用户输入文件流,读模式
     //private StreamWriter swUserInput = null;//用户输入写文件
     //private StreamReader srUserInput = null;//用户输入读文件
     private BackgroundWorker bwInit = new BackgroundWorker();
     #endregion
     #region 软件启动
     //构造函数
     public MainForm()
     {
         FuncLib.CheckSingleThread();
         InitializeComponent();
 
         exeName = Process.GetCurrentProcess().ProcessName;
 
         Rectangle rt = Screen.PrimaryScreen.WorkingArea;
         int formwidth = this.Width;
         int formheight = this.Height;
         int startx = Convert.ToInt32(((float)rt.Width - (float)this.Width) / 2.0f);
         int starty = Convert.ToInt32((float)rt.Height * 2.0f / 3.0);
         MainFormStartPosition = new Point(startx, starty);
         frmToDock();
         enumCurrentSE = EnumSearchEngine.GOOGLE_WEB;
         //注册委托事件
         FormBrowser.FormBrowserClosed  = new FormBrowserClosedHandler(FormBrowser_HandleBackFormBrowserClosed);
         FormBrowser.FormBrowserNewWindow =new FormBrowserNewWindowHandler(FormBrowser_FormBrowserNewWindow);
         FormConfig.SetGlobalKey =new GlobleKeySetHandler(FormConfig_SetGlobalKey);
         FormBrowserContainer.TabAllClosed =new TabAllClosedHandler(FormBrowserContainer_TabAllClosed);
         FormBrowserContainer.FormSizeChanged =new FormSizeChangedHandler(FormBrowserContainer_FormSizeChanged);
         FormEyeGuard.EventEyeGuard =new HandleEyeGuard(FormEyeGuard_EventEyeGuard);           
         bwInit = new BackgroundWorker();
         bwInit.DoWork  = new DoWorkEventHandler(bwInit_DoWork);
         bwInit.RunWorkerAsync();//执行耗时操作,避免界面无响应
     }
     //系统加载事件
     private void MainForm_Load(object sender, EventArgs e)
     {
         int startx = MainFormStartPosition.X - Convert.ToInt32(((float)fbc.Width - (float)this.Width) / 2.0f);
         int starty = MainFormStartPosition.Y - fbc.Height;
         WebFormStartPosition.X = startx;
         WebFormStartPosition.Y = starty;
 
         MainFormCollapsed();
         try
         {
             //fswUserInput = new FileStream("UserInput.log", FileMode.Open, FileAccess.Write);
             //fsrUserInput = new FileStream("UserInput.log", FileMode.Open, FileAccess.Read);
             //swUserInput = new StreamWriter(fswUserInput);
             //srUserInput = new StreamReader(fsrUserInput);
             flagGlobalHotKeySet = HotKey.RegisterHotKey(this.Handle, WIN_S, HotKey.KeyModifiers.WindowsKey, Keys.S);
             flagGlobalHotKeySet=HotKey.RegisterHotKey(this.Handle, CTL_ALT_A, HotKey.KeyModifiers.Alt | HotKey.KeyModifiers.Ctrl, Keys.A);
             flagGlobalHotKeySet = HotKey.RegisterHotKey(this.Handle, CTL_ALT_SHIFT_S, HotKey.KeyModifiers.Shift| HotKey.KeyModifiers.Alt | HotKey.KeyModifiers.Ctrl, Keys.S);
             flagGlobalHotKeySet = HotKey.RegisterHotKey(this.Handle, CTL_ALT_SHIFT_X, HotKey.KeyModifiers.Shift|HotKey.KeyModifiers.Alt | HotKey.KeyModifiers.Ctrl, Keys.X);
             flagGlobalHotKeySet = HotKey.RegisterHotKey(this.Handle, CTL_ALT_SHIFT_R, HotKey.KeyModifiers.Shift | HotKey.KeyModifiers.Alt | HotKey.KeyModifiers.Ctrl, Keys.R);
             flagGlobalHotKeySet = HotKey.RegisterHotKey(this.Handle, WIN_F12, HotKey.KeyModifiers.WindowsKey, Keys.F12);
             if (!flagGlobalHotKeySet)
             {
                 throw new Exception("注册全局快捷键失败!");
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "出错了");
         }
     }
     //启动时后台运行的程序
     private void bwInit_DoWork(object sender, DoWorkEventArgs e)
     {           
         //... 创建目录、读取文件、生成快捷方式
         //创建应用程序配置目录
         string dirAppData = Environment.SpecialFolder.ApplicationData.ToString();
         if (Directory.Exists(dirAppData))
         {
              
         }
         //开机启动及生成桌面快捷方式
         if (FuncLib.CheckStartUPSet())
         {
             //创建快捷方式s
             FuncLib.CreateDesktopLnk(DISPLAY_NAME);
             toolStripMenuItemStartUp.Checked = true;
         }
         ////加入系统启动项
         //if (FuncLib.SetStartUp(true, exeName))
         //{
         //    toolStripMenuItemStartUp.Checked = true;
         //}
     }
     #endregion
     #region 网络通信
     private void InitUdpCommServer()
     {
         udpCommServer = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
         IPEndPoint ipeComm = new IPEndPoint(IPAddress.Any, PORT_COMM);
         udpCommServer.Bind(ipeComm);
         ThreadPool.QueueUserWorkItem(this.HandleUdpComm, ipeComm);
     }
 
     private void InitUdpMsgServer()
     {
         udpMsgServer = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
         IPEndPoint ipeMsg = new IPEndPoint(IPAddress.Any, PORT_COMM);
         udpMsgServer.Bind(ipeMsg);
         ThreadPool.QueueUserWorkItem(this.HandleUdpMsg, ipeMsg);
     }
 
     private void InitUdpFileServer()
     {
         udpFileServer = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
         IPEndPoint ipeFile = new IPEndPoint(IPAddress.Any, PORT_COMM);
         udpFileServer.Bind(ipeFile);
         ThreadPool.QueueUserWorkItem(this.HandleUdpFile, ipeFile);
     }
 
     private void HandleUdpComm(object state)
     {
 
     }
 
     private void HandleUdpMsg(object state)
     {
 
     }
 
     private void HandleUdpFile(object state)
     {
 
     }
 
     #endregion
     #region 界面相关
 
     private void SearchInNewWindow(EnumSearchEngine enumSE)
     {
         if (fbc==null||fbc.Visible==false)
         {
             fbc = new FormBrowserContainer();
             fbc.StartPosition = FormStartPosition.Manual;
             fbc.Location = new Point(WebFormStartPosition.X, WebFormStartPosition.Y);
             fbc.ShowInTaskbar = false;
             fbc.Show();
         }
 
         fbc.BringToFront();
         fb = new FormBrowser(tbSearch.Text, enumSE);
         fb.Dock = DockStyle.Fill;
         //将搜索文本存入文件流
         //swUserInput.WriteLine(DateTime.Now.ToString("yy-MM-dd_HH:mm:ss" " " fb.searchstr));
         //fb.enumSE = enumSE;
         fbc.AddNewTab(fb);
         listFormBrowser.Add(fb);
     }
 
     private void ShowHelpForm(int type)
     {
         fh = new FormHelp();
         fh.ShowInTaskbar = false;
         fh.ShowIcon = false;
         switch (type)
         {
             case 0:
                 {
                      
                     fh.StartPosition = FormStartPosition.Manual;
                     fh.Location = new Point(this.Location.X - (fh.Width / 2 - this.Width / 2), this.Location.Y - fh.Height);
                     fh.Show();
                 }
                 break;
             case 1:
                 {
                     fh.StartPosition = FormStartPosition.CenterScreen;
                     fh.Location = new Point(this.Location.X - (fh.Width / 2 - this.Width / 2), this.Location.Y - fh.Height);
                     fh.Show();
                 }
                 break;
         }
          
     }
      
     private void MainFormExpand()
     {
         this.Size = new Size(584, 64);
         flagFormExpand = true;
         this.Refresh();
     }
 
     private void MainFormCollapsed()
     {
         this.Size = new Size(584, 40);
         flagFormExpand = false;
         this.Refresh();
     }
 
     private void ShowMainForm()
     {
         this.Visible = true;
         toolStripMenuItemDisplay.Text = "隐藏界面";
         flagFormShow = true;
     }
 
     private void HideMainForm()
     {
         this.Visible = false;
         toolStripMenuItemDisplay.Text = "显示界面";
         flagFormShow = false;
          
     }
 
     private void frmToMiddle()
     {
         //...动画效果
         this.Location = MainFormStartPosition;
         //FormEffect.Swift(this);
         flagFormDocked = false;
         if (fbc != null)
         {
             //fbc.Visible = true;
             fbc.BringToFront();
         }
         this.BringToFront();
         this.Activate();
         this.Visible = true;
         tbSearch.Focus();
     }
 
     private void frmToDock()
     {
         //...动画效果
         this.Location = new Point(MAIN_FORM_DOCK_X, MainFormStartPosition.Y);
         flagFormDocked = true;
         ckbDock.Checked = true;
 
         if (fbc != null)
         {
             //fbc.Visible = false;
             fbc.SendToBack();
         }
         if (!flagFormShow)
         {
             this.Visible = false;
         }
         //收起搜索引擎设置界面
         if (flagFormExpand)
         {
             flagFormExpand = false;
             MainFormCollapsed();
             ckbShowSE.Checked = false;
         }
     }
     #endregion
     #region 右键菜单
     //退出程序
     private void toolStripMenuItemQuit_Click(object sender, EventArgs e)
     {
         if (MessageBox.Show("确定退出本软件?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
         Application.Exit();
     }
     //显示隐藏
     private void toolStripMenuItemDisplay_Click(object sender, EventArgs e)
     {
         if (flagFormShow)
         {
             HideMainForm();
         }
         else
         {
             ShowMainForm();
         }
     }
     //帮助窗口
     private void toolStripMenuItemHelp_Click(object sender, EventArgs e)
     {
         if (flagFormDocked)
         {
             ShowHelpForm(1);
         }
         else
         {
             ShowHelpForm(0);               
         }
     }
     //开机启动
     private void toolStripMenuItemStartUp_Click(object sender, EventArgs e)
     {
         if (toolStripMenuItemStartUp.Checked)//设置开机不启动
         {
             if (FuncLib.SetStartUp(false, exeName))
             {
                 MessageBox.Show("取消开机启动成功","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                 toolStripMenuItemStartUp.Checked = false;
             }
             else
             {
                 MessageBox.Show("取消开机启动失败","提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
         }
         else//设置开机启动
         {
             if (FuncLib.CheckStartUPSet())
             {
                 MessageBox.Show("设置开机启动成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 toolStripMenuItemStartUp.Checked = true;
             }
             else
             {
                 MessageBox.Show("设置开机启动失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
     }
     //生成快捷方式
     private void toolStripMenuItemShortCut_Click(object sender, EventArgs e)
     {
         if (FuncLib.CreateDesktopLnk(DISPLAY_NAME))
         {
             MessageBox.Show("创建快捷方式到桌面成功","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
         }
         else
         {
             MessageBox.Show("创建快捷方式到桌面失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
     }
     //护眼模式控制
     private void tmiEyeGuard_Click(object sender, EventArgs e)
     {
         if (flagEyeGuardOpen)
         {
             feyeGuard.StopEyeGuard();
             flagEyeGuardOpen = false;
             tmiEyeGuard.Text = "开启护眼";
             prbEyeGuardInterval.Visible = false;
             return;
         }
         feyeGuard.flagEyeGuard = false;
         if(feyeGuard.ShowDialog() == System.Windows.Forms.DialogResult.Yes)
         {
             prbEyeGuardInterval.Maximum = feyeGuard.nRestInterval;
             prbEyeGuardInterval.Visible = true;
             tmiEyeGuard.Text = "停止护眼";
             flagEyeGuardOpen = true;
         }
     }
     //系统设置
     private void tmiSystemSet_Click(object sender, EventArgs e)
     {
         FormConfig fc = new FormConfig();
         fc.StartPosition = FormStartPosition.CenterScreen;
         fc.ShowDialog(this);
     }
     //截屏
     private void tmiCaptrueScreen_Click(object sender, EventArgs e)
     {
         CaptureScreen();
     }
     //系统关机
     private void tmiSystemShutDown_Click(object sender, EventArgs e)
     {
         if(MessageBox.Show("确定关闭计算机?","提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Question)== System.Windows.Forms.DialogResult.OK)
         WindowsController.ExitWindows(RestartOptions.ShutDown, true);
     }
     //系统重启
     private void tmiSystemRestart_Click(object sender, EventArgs e)
     {
         if (MessageBox.Show("确定重启计算机?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
         WindowsController.ExitWindows(RestartOptions.Reboot, true);
     }
     //系统注销
     private void tmiSystemLogoff_Click(object sender, EventArgs e)
     {
         if (MessageBox.Show("确定注销计算机?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
         WindowsController.ExitWindows(RestartOptions.LogOff, true);
     }
     //系统休眠
     private void tmiSystemHibernate_Click(object sender, EventArgs e)
     {
         //if (MessageBox.Show("确定休眠计算机?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
         WindowsController.ExitWindows(RestartOptions.Hibernate, true);
     }
     //系统睡眠/挂起
     private void tmiSystemSleep_Click(object sender, EventArgs e)
     {
         if (MessageBox.Show("确定挂起计算机?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
         WindowsController.ExitWindows(RestartOptions.Suspend, true);
     }
     //闹钟设置
     private void tmiAlarmClockSet_Click(object sender, EventArgs e)
     {
         FormAlarmClockSet fac = new FormAlarmClockSet();
         fac.StartPosition = FormStartPosition.CenterScreen;
         fac.ShowDialog();
     }
     #endregion
     #region 事件集合
     private void MainForm_Click(object sender, EventArgs e)
     {
         if (Control.ModifierKeys == Keys.Alt)
         {
             if (cdgMainForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
             {
                 this.BackColor = cdgMainForm.Color;
             }
         }
     }
 
     private void MainForm_MouseEnter(object sender, EventArgs e)
     {
         if (fbc != null)
         {
             fbc.BringToFront();
             fbc.Focus();
         }
     }
 
     private void MainForm_MouseDown(object sender, MouseEventArgs e)
     {
         if (Control.ModifierKeys == Keys.Control)
         {
             FuncLib.StartDrag(this.Handle);
         }
     }
 
     private void ckbDock_CheckedChanged(object sender, EventArgs e)
     {
         if (!ckbDock.Checked)
         {
             frmToDock();
         }
     }
 
     private void MainForm_Paint(object sender, PaintEventArgs e)
     {
         Graphics g = e.Graphics;
         SolidBrush sb1 = new SolidBrush(Color.LightGray);
         SolidBrush sb2 = new SolidBrush(Color.Gray);
         Pen p1 = new Pen(sb1);
         Pen p2= new Pen(sb2);
         g.DrawRectangle(p2, 0, 0, this.Width - 1, this.Height - 1);
         g.DrawLine(p1, 0, 0, this.Width - 1, 0);
         g.DrawLine(p1,0,0,0,this.Height-1);
         //g.DrawLine(p2,this.Width-1,0,this.Width-1,this.Height-1);
         sb1.Dispose();
         sb2.Dispose();
         p1.Dispose();
         p2.Dispose();
         g.Dispose();
     }
      
     private void FormBrowserContainer_TabAllClosed(object sender)
     {
         fbc.Close();
         fbc = null;
     }
 
     private void FormConfig_SetGlobalKey(object sender)
     {
         if (flagGlobalHotKeySet)
         {
             MessageBox.Show("全局快捷键Win S已经注册成功", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else
         {
             flagGlobalHotKeySet = HotKey.RegisterHotKey(Handle, WIN_S, HotKey.KeyModifiers.WindowsKey, Keys.S);
             if (!flagGlobalHotKeySet)
             {
                 MessageBox.Show("注册全局快捷键Win S失败", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
         }
     }
 
     private void FormBrowser_HandleBackFormBrowserMaximized(FormWindowState fws)
     {
         switch (fws)
         {
             case FormWindowState.Maximized:
                 //将主搜索框停靠
                 if (!flagFormDocked)
                 {
                     frmToDock();
                 }
                 break;
             case FormWindowState.Normal:
                 if (flagFormDocked)
                 {
                     frmToMiddle();
                 }
                 break;
         }
     }
     //收到某个浏览器窗体关闭事件
     private void FormBrowser_HandleBackFormBrowserClosed(object sender)
     {
         FormBrowser fb=sender as FormBrowser;
         //int index = GetFormBrowserIndex(fb);
         //listFormBrowser.RemoveAt(index);
         listFormBrowser.Remove(fb);
     }
 
     private int GetFormBrowserIndex(FormBrowser fb)
     {
         return listFormBrowser.FindIndex(delegate(FormBrowser ent)
         {
             return ent.Equals(fb);
         });
     }
 
     private void rdb_CheckedChanged(object sender, EventArgs e)
     {
         if (rdbGoogleWeb.Checked)
         {
             enumCurrentSE = EnumSearchEngine.GOOGLE_WEB;
             //lbSEType.Text = "谷歌";
         }
         else if (rdbBaiduWeb.Checked)
         {
             enumCurrentSE = EnumSearchEngine.BAIDU_WEB;
             //lbSEType.Text="百度";
         }
         else if (rdbBaiduBaike.Checked)
         {
             enumCurrentSE = EnumSearchEngine.BAIDU_BAIKE;
             //lbSEType.Text = "百科";
         }
         else if (rdbBaiduZhiDao.Checked)
         {
             enumCurrentSE = EnumSearchEngine.BAIDU_ZHIDAO;
             //lbSEType.Text = "知道";
         }
         else if (rdbBaiduMusic.Checked)
         {
             enumCurrentSE = EnumSearchEngine.BAIDU_MUSIC;
             //lbSEType.Text = "音乐";
         }
         else if (rdbBaiduApp.Checked)
         {
             enumCurrentSE = EnumSearchEngine.BAIDU_APP;
             //lbSEType.Text = "应用";
         }
         else if (rdbIcon.Checked)
         {
             enumCurrentSE = EnumSearchEngine.ICON_EASY;
             //lbSEType.Text = "图标";               
         }
         else if (rdbBaiduWenKu.Checked)
         {
             enumCurrentSE = EnumSearchEngine.BAIDU_WENKU;
             //lbSEType.Text = "文库";
         }
         else if (rdbBaiduMap.Checked)
         {
             enumCurrentSE = EnumSearchEngine.BAIDU_MAP;
             //lbSEType.Text = "地图";
         }
         else if (rdbFanyi.Checked)
         {
             enumCurrentSE = EnumSearchEngine.GOOGLE_FANYI;
         }
     }
 
     private void ckbShowSE_CheckedChanged(object sender, EventArgs e)
     {
         if (ckbShowSE.Checked)
         {
             MainFormExpand();
         }
         else
         {
             MainFormCollapsed();
         }
     }
 
     private void ntiMain_DoubleClick(object sender, EventArgs e)
     {
         if (flagFormDocked)
         {
             frmToMiddle();
         }
         else
         {
             frmToDock();
         }
     }
 
     protected override void WndProc(ref Message m)
     {
         const int WM_HOTKEY = 0x0312;
         switch (m.Msg)
         {
             case WM_HOTKEY:
                 switch (m.WParam.ToInt32())
                 {
                     case 100://win s
                         this.Visible = true;
                         if (flagFormDocked)
                         {
                             frmToMiddle();
                         }
                         else
                         {
                             if (listFormBrowser.Count > 0 || tbSearch.Focused == false)//已经打开子窗口,让主窗口重新聚焦
                             {
                                 if (fbc != null)
                                 {
                                     fbc.BringToFront();
                                     fbc.Activate();
                                 }
                                 this.BringToFront();
                                 this.Activate();
                                 tbSearch.Focus();
                             }
                             else
                             {
                             frmToDock();
                             }
                         }
                         break;
                     case CTL_ALT_A://ctrl alt a 截屏
                         {
                             CaptureScreen();
                         }
                         break;
                     case CTL_ALT_SHIFT_X:
                         {
                             tmiSystemShutDown_Click(null, null);
                         }
                         break;
                     case CTL_ALT_SHIFT_S:
                         {
                             tmiSystemHibernate_Click(null, null);
                         }
                         break;
                     case CTL_ALT_SHIFT_R:
                         {
                             tmiSystemRestart_Click(null,null);
                         }
                         break;
                     case WIN_F12:
                         {
                             SetWindowBlack();
                         }
                         break;
                 }
                 break;
         }
         base.WndProc(ref m);
     }
    
     private void tbSearch_DoubleClick(object sender, EventArgs e)
     {
         tbSearch.SelectAll();
     }
 
     private void fb_Paint(object sender, PaintEventArgs e)
     {
         e.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.Black)), 0, 0, 119, 94);
     }
 
     private void tbSearch_KeyUp(object sender, KeyEventArgs e)
     {
         if (!e.Shift && !e.Control && !e.Alt)
         {
             switch (e.KeyCode)
             {
                 case Keys.Enter:
                     //MessageBox.Show("按下enter");
                     break;
             }
         }
     }
 
     private void btnSearch_Click(object sender, EventArgs e)
     {
         if (Control.ModifierKeys == Keys.Shift)//恢复默认图标
         {
             btnSearch.Image = global::DeskTopOnline.Properties.Resources.search_16;
             return;
         }
         if (Control.ModifierKeys == Keys.Alt)//更换图标
         {
             //if (ofdChangeIcon.ShowDialog() == System.Windows.Forms.DialogResult.OK)//更换图标
             //{
             //    try
             //    {
             //        //将图标拷贝到配置目录中去
             //        //替换图标
             //        Bitmap img = new Bitmap(ofdChangeIcon.FileName);                      
             //        //img.SetResolution(16f, 16f);
             //        //btnSearch.Image = Image.FromFile(ofdChangeIcon.FileName);
             //        btnSearch.Image = img;
             //    }
             //    catch(Exception ex)
             //    {
             //        MessageBox.Show(ex.Message,"异常");
             //    }
             //}
             FormPortraitGenerator fpg = new FormPortraitGenerator();
             if (flagFormDocked)
             {
                 fpg.StartPosition = FormStartPosition.CenterScreen;
             }
             else
             {
                 fpg.StartPosition = FormStartPosition.Manual;
                 fpg.Location = new Point(this.Location.X - (fpg.Width / 2 - this.Width / 2), this.Location.Y - fpg.Height);
             }
             if (fpg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
             {
                 btnSearch.Image = fpg.GeneratedImg;
                 fpg.Close();
             }
         }
         else
         {
             if (flagFormDocked)//缩进状态先弹出来
             {
                 frmToMiddle();
             }
             else
             {
                 if (tbSearch.Text.Trim(' ') == "")
                 {
                     tbSearch.Text = "";
                     frmToDock();
                     return;
                 }
                 if (FuncLib.IsURL(tbSearch.Text) || FuncLib.IsURL(@"http://"   tbSearch.Text))
                 {
                     enumCurrentSE = EnumSearchEngine.OPEN_URL;
                 }
                 SearchInNewWindow(enumCurrentSE);
             }
         }
     }
 
     //private void MainForm_KeyDown(object sender, KeyEventArgs e)
     //{
     //    //ctrl组合键
     //    if (e.Control && !e.Shift && !e.Alt)
     //    {
     //        switch (e.KeyCode)
     //        {
     //            case Keys.Enter://使用google搜索
     //                //lbSEType.Text = "谷歌";
     //                enumCurrentSE = EnumSearchEngine.GOOGLE_WEB;
     //                break;
     //            //case Keys.Enter://使用百度搜索
     //            //    if (tbSearch.Text == "")
     //            //        return;
     //            //    SearchInNewWindow(EnumSearchEngine.BAIDU_WEB);
     //            //    break;                  
     //            case Keys.I:
     //                //lbSEType.Text = "图标";
     //                enumCurrentSE = EnumSearchEngine.ICON_EASY;
     //                break;
     //        }
     //    }
     //    //alt组合键
     //    if (e.Alt && !e.Shift && !e.Control)
     //    {
     //        switch (e.KeyCode)
     //        {
     //            case Keys.Enter:
     //                //lbSEType.Text = "百度";
     //                enumCurrentSE = EnumSearchEngine.BAIDU_WEB;
 
     //                break;
     //        }
     //    }
 
     //    //shift 组合键
     //    if (e.Shift && !e.Control && !e.Alt)
     //    {
     //        switch (e.KeyCode)
     //        {
     //            case Keys.Enter:
     //                //lbSEType.Text = "知道";
     //                enumCurrentSE = EnumSearchEngine.BAIDU_ZHIDAO;
 
     //                break;
     //        }
     //    }
 
     //    //ctrl shift组合键
     //    if (e.Control && e.Shift && !e.Alt)
     //    {
     //        switch (e.KeyCode)
     //        {
     //            case Keys.Enter:
     //                //lbSEType.Text = "百科";
     //                enumCurrentSE = EnumSearchEngine.BAIDU_BAIKE;
     //                break;
     //        }
     //    }
     //    //ctrl alt组合键
     //    if (e.Control && e.Alt && !e.Shift)
     //    {
     //        switch (e.KeyCode)
     //        {
     //            case Keys.Enter:
     //                //lbSEType.Text = "音乐";
     //                enumCurrentSE = EnumSearchEngine.BAIDU_MUSIC;
     //                break;
     //        }
     //    }
     //    //alt shift组合键
     //    if (e.Alt && e.Shift && !e.Control)
     //    {
 
     //        switch (e.KeyCode)
     //        {
     //            case Keys.Enter:
     //                //lbSEType.Text = "文库";
     //                enumCurrentSE = EnumSearchEngine.BAIDU_WENKU;
     //                break;
 
     //        }
     //    }
     //    //ctrl alt shift组合键
     //    if (e.Control && e.Alt && e.Shift)
     //    {
     //        switch (e.KeyCode)
     //        {
     //            case Keys.Enter:
     //                //lbSEType.Text = "地图";
     //                enumCurrentSE = EnumSearchEngine.BAIDU_MAP;
     //                break;
     //        }
     //    }
     //}
 
     private void MainForm_KeyUp(object sender, KeyEventArgs e)
     {
         //未按下组合键
         if ((e.Shift | e.Control | e.Alt) != true)
         {
             switch (e.KeyCode)
             {
                 case Keys.Escape://原Escape收起改为Win S收起
                     //this.Close();
                     //this.Location = new Point(btnSearch.Location.X-this.Location.X,this.Location.Y);
                     frmToDock();
                     break;
                 case Keys.Enter://Enter键开始搜索
                     //if (!tbSearch.Focused)
                     //{
                         btnSearch_Click(null, null);
                     //}
                     break;
                 case Keys.F1:
                     toolStripMenuItemHelp_Click(null,null);
                     break;
                 //case Keys.Enter:
                 //    if (tbSearch.Text == "")
                 //        return;
                 //    SearchInNewWindow(EnumSearchEngine.GOOGLE_WEB);
                 //    break;
             }
         }
         //ctrl组合键
         if (e.Control && !e.Shift && !e.Alt)
         {
             switch (e.KeyCode)
             {
                 case Keys.A:
                     tbSearch.SelectAll();
                     break;
                 case Keys.W:
                     if (listFormBrowser.Count >= 1)
                     {
                         listFormBrowser[listFormBrowser.Count - 1].Dispose();//关闭最后一个窗体
                     }
                     break;
                 case Keys.S:
                     ckbShowSE.Checked = !ckbShowSE.Checked;
                     break;
                 case Keys.Enter://使用google搜索
                     if (tbSearch.Text == "")
                         return;
                     SearchInNewWindow(EnumSearchEngine.GOOGLE_WEB);
                     SetSEChoice(EnumSearchEngine.GOOGLE_WEB);
                     break;
                 //case Keys.Enter://使用百度搜索
                 //    if (tbSearch.Text == "")
                 //        return;
                 //    SearchInNewWindow(EnumSearchEngine.BAIDU_WEB);
                 //    break;
                 case Keys.Back:
                     tbSearch.Clear();
                     break;
                 case Keys.I:
                     if (tbSearch.Text == "")
                         return;
                     SearchInNewWindow(EnumSearchEngine.ICON_EASY);
                     SetSEChoice(EnumSearchEngine.ICON_EASY);
                     break;
             }
         }
         //alt组合键
         if (e.Alt && !e.Shift && !e.Control)
         {
             switch (e.KeyCode)
             {
                 case Keys.Enter:
                     if (tbSearch.Text == "")
                         return;
                     SearchInNewWindow(EnumSearchEngine.BAIDU_WEB);
                     SetSEChoice(EnumSearchEngine.BAIDU_WEB);
                     break;
             }
         }
 
         //shift 组合键
         if (e.Shift && !e.Control && !e.Alt)
         {
             switch (e.KeyCode)
             {
                 case Keys.Enter:
                     if (tbSearch.Text == "")
                         return;
                     SearchInNewWindow(EnumSearchEngine.BAIDU_ZHIDAO);
                     SetSEChoice(EnumSearchEngine.BAIDU_ZHIDAO);
                     break;
             }
         }
 
         //ctrl shift组合键
         if (e.Control && e.Shift && !e.Alt)
         {
             switch (e.KeyCode)
             {
                 case Keys.Enter:
                     if (tbSearch.Text == "")
                         return;
                     SearchInNewWindow(EnumSearchEngine.BAIDU_BAIKE);
                     SetSEChoice(EnumSearchEngine.BAIDU_BAIKE);
                     break;
                 case Keys.W:
                     if (fbc != null)
                     {
                         fbc.Close();
                     }
                     listFormBrowser.Clear();
                     break;
             }
         }
         //ctrl alt组合键
         if (e.Control && e.Alt && !e.Shift)
         {
             switch (e.KeyCode)
             {
                 case Keys.Enter:
                     if (tbSearch.Text == "")
                         return;
                     SearchInNewWindow(EnumSearchEngine.BAIDU_MUSIC);
                     SetSEChoice(EnumSearchEngine.BAIDU_MUSIC);
                     break;
             }
         }
         //alt shift组合键
         if (e.Alt && e.Shift && !e.Control)
         {
             switch (e.KeyCode)
             {
                 case Keys.Enter:
                     if (tbSearch.Text == "")
                         return;
                     SearchInNewWindow(EnumSearchEngine.BAIDU_WENKU);
                     SetSEChoice(EnumSearchEngine.BAIDU_WENKU);
                     break;
             }
         }
         //ctrl alt shift组合键
         if (e.Control && e.Alt && e.Shift)
         {
             switch (e.KeyCode)
             {
                 case Keys.Enter:
                     if (tbSearch.Text == "")
                         return;
                     SearchInNewWindow(EnumSearchEngine.BAIDU_MAP);
                     SetSEChoice(EnumSearchEngine.BAIDU_MAP);
                     break;
             }
         }
     }
 
     private void FormEyeGuard_EventEyeGuard(int n)
     {
         prbEyeGuardInterval.Invoke(new EventHandler(delegate
         {
             prbEyeGuardInterval.Value = n;
             if (n < 60)
             {
                 FormEffect.Blink(this);
             }
         }));
     }
 
     private void FormBrowserContainer_FormSizeChanged(FormWindowState fws)
     {
         if (fws == FormWindowState.Maximized)
         {
             this.Visible = false;
         }
         else
         {
             this.Visible = true;
         }
     }
 
     private void FormBrowser_FormBrowserNewWindow(string url)
     {
         fb = new FormBrowser(url, EnumSearchEngine.OPEN_URL);
         fb.Dock = DockStyle.Fill;
         //将搜索文本存入文件流
         //swUserInput.WriteLine(DateTime.Now.ToString("yy-MM-dd_HH:mm:ss" " " fb.searchstr));
         //fb.enumSE = enumSE;
         fbc.AddNewTab(fb);
         listFormBrowser.Add(fb);
     }
     #endregion
     #region 功能函数
     //黑屏
     private void SetWindowBlack()
     {
         FormRestScreen fmRest = new FormRestScreen();
         fmRest.TotalRestTime = 5;
         fmRest.ShowDialog();
     }
     //截屏
     private void CaptureScreen()
     {
         if (flagFormShow)
         {
             this.Hide();
         }
         Thread.Sleep(20);
         CaptureImageTool cit = new CaptureImageTool();
         cit.ShowDialog();
         if (flagFormShow)
         {
             this.Show();
         }
     }
     //设置搜索引擎
     private void SetSEChoice(EnumSearchEngine ese)
     {
         switch (ese)
         {
             case EnumSearchEngine.GOOGLE_WEB:
                 rdbGoogleWeb.Checked = true;
                 break;
             case EnumSearchEngine.BAIDU_WEB:
                 rdbBaiduWeb.Checked = true;
                 break;
             case EnumSearchEngine.BAIDU_ZHIDAO:
                 rdbBaiduZhiDao.Checked = true;
                 break;
             case EnumSearchEngine.BAIDU_BAIKE:
                 rdbBaiduBaike.Checked = true;
                 break;
             case EnumSearchEngine.BAIDU_WENKU:
                 rdbBaiduWenKu.Checked = true;
                 break;
             case EnumSearchEngine.BAIDU_MUSIC:
                 rdbBaiduMusic.Checked = true;
                 break;
             case EnumSearchEngine.BAIDU_MAP:
                 rdbBaiduMap.Checked = true;
                 break;
             case EnumSearchEngine.BAIDU_APP:
                 rdbBaiduApp.Checked = true;
                 break;
             case EnumSearchEngine.ICON_EASY:
                 rdbIcon.Checked = true;
                 break;
             case EnumSearchEngine.LOCAL_FILE:
                 rdbFanyi.Checked = true;
                 break;
         }
     }
     //获取搜索引擎
     private EnumSearchEngine GetSEChoice()
     {
         EnumSearchEngine ese = new EnumSearchEngine();
         if (rdbGoogleWeb.Checked)
         {
             ese = EnumSearchEngine.GOOGLE_WEB;
         }
         else if (rdbBaiduWeb.Checked)
         {
             ese = EnumSearchEngine.BAIDU_WEB;
         }
         else if (rdbBaiduZhiDao.Checked)
         {
             ese = EnumSearchEngine.BAIDU_ZHIDAO;
         }
         else if (rdbBaiduBaike.Checked)
         {
             ese = EnumSearchEngine.BAIDU_BAIKE;
         }
         else if (rdbBaiduMap.Checked)
         {
             ese = EnumSearchEngine.BAIDU_MAP;
         }
         else if (rdbFanyi.Checked)
         {
             ese = EnumSearchEngine.LOCAL_FILE;
         }
         else if (rdbBaiduMusic.Checked)
         {
             ese = EnumSearchEngine.BAIDU_MUSIC;
         }
         return ese;
     }
     #endregion
     #region 资源释放
     private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
     {
         HotKey.UnregisterHotKey(this.Handle, WIN_S);
         HotKey.UnregisterHotKey(this.Handle,CTL_ALT_A);
         HotKey.UnregisterHotKey(this.Handle,CTL_ALT_SHIFT_S);
         HotKey.UnregisterHotKey(this.Handle,CTL_ALT_SHIFT_X);
         HotKey.UnregisterHotKey(this.Handle,CTL_ALT_SHIFT_R);
         HotKey.UnregisterHotKey(this.Handle,WIN_F12);
     }
     #endregion
 }

标签: 截图 C# 快捷方式

实例下载地址

C# 仿搜狗/360 快捷搜索栏 源码下载(实现了开机启动/手动截图/快捷方式/快捷键等)

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警