效果展示 效果展示
下载 FormDisplayControl.dll 提取码:shsh
引用 1 2 3 4 5 6 7 8 9 10 11 12 public void invisibility (Form form ){ SHSHControl shshCtrl = new SHSHControl(); shshCtrl.Control(form); shshCtrl.DelControl(form); }
Code 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 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows.Forms;namespace FormDisplayControl { public class SHSHControl { Timer timerFormInvisibility = new Timer(); Form Form = null ; public SHSHControl () { } public void Control (Form form ) { this .Form = form; timerFormInvisibility.Interval = 1000 ; timerFormInvisibility.Tick += new EventHandler(timerFormDisplay_Tick); Form.MouseEnter += new EventHandler(formDisplay); Form.MouseLeave += new EventHandler(formInvisibility); ctrlsAddMethod(Form.Controls); } public void DelControl (Form form ) { this .Form = form; Form.MouseEnter -= new EventHandler(formDisplay); Form.MouseLeave -= new EventHandler(formInvisibility); ctrlsDelMethod(Form.Controls); } private void ctrlsAddMethod (Control.ControlCollection ctrls ) { foreach (Control ctr in ctrls) { if (ctr.Controls.Count > 0 ) { ctrlsAddMethod(ctr.Controls); } else { ctr.MouseEnter += new EventHandler(formDisplay); ctr.MouseLeave += new EventHandler(formInvisibility); } } } private void ctrlsDelMethod (Control.ControlCollection ctrls ) { foreach (Control ctr in ctrls) { if (ctr.Controls.Count > 0 ) { ctrlsDelMethod(ctr.Controls); } else { ctr.MouseEnter -= new EventHandler(formDisplay); ctr.MouseLeave -= new EventHandler(formInvisibility); } } } private void formInvisibility (object sender, EventArgs e ) { timerFormInvisibility.Start(); } private void formDisplay (object sender, EventArgs e ) { try { if (judgeMouseIn()) { timerFormInvisibility.Stop(); Form.Opacity = 1 ; } } catch { } } private void timerFormDisplay_Tick (object sender, EventArgs e ) { try { if (!judgeMouseIn()) { Form.Opacity = 0.5 ; timerFormInvisibility.Stop(); } } catch { } } private bool judgeMouseIn () { int x = Cursor.Position.X; int y = Cursor.Position.Y; int l = Form.Left; int r = Form.Right; int t = Form.Top; int b = Form.Bottom; if (x - l > 8 && r - x > 8 && y - t > 30 && b - y > 8 ) { return true ; } return false ; } } }