1. 程式人生 > >C#製作高仿360安全衛士窗體

C#製作高仿360安全衛士窗體

複製程式碼
  1 #region 方法
  2 protected void SystemBtnSet()
  3 {
  4     int btnTop = 0;
  5     int btnRight = 6;
  6     int panelMargin = 2;
  7     if (WindowState == FormWindowState.Maximized && FormBorderStyle != System.Windows.Forms.FormBorderStyle.None)
  8     {
  9         btnTop = 10
; 10 btnRight = 16; 11 panelMargin = 10; 12 } 13 this.ContentPanel.Location = new Point(panelMargin, _TopHeight); 14 this.ContentPanel.Size = new Size(ClientRectangle.Width - (panelMargin * 2), ClientRectangle.Height - _TopHeight - panelMargin); 15 16 switch ((int
)_FormSystemBtnSet) 17 { 18 case 0: 19 btn_close.BackImg = btn_closeImg; 20 btn_close.Location = new Point(this.Width - 32, btnTop); 21 btn_mini.BackImg = btn_miniImg; 22 btn_mini.Location = new Point(this.Width - 86, btnTop); 23 btn_max.BackImg = btn_maxImg;
24 btn_restore.BackImg = btn_restoreImg; 25 if (WindowState == FormWindowState.Normal) 26 { 27 btn_max.Location = new Point(this.Width - 59, btnTop); 28 btn_restore.Location = new Point(this.Width - 59, -22); 29 } 30 else 31 { 32 btn_max.Location = new Point(this.Width - 59, -22); 33 btn_restore.Location = new Point(this.Width - 59, btnTop); 34 } 35 break; 36 case 1: 37 btn_close.BackImg = btn_closeImg; 38 btn_close.Location = new Point(this.Width - 32, -22); 39 btn_max.BackImg = btn_maxImg; 40 btn_max.Location = new Point(this.Width - 59, -22); 41 btn_mini.BackImg = btn_miniImg; 42 btn_mini.Location = new Point(this.Width - 86, -22); 43 btn_restore.BackImg = btn_restoreImg; 44 btn_restore.Location = new Point(this.Width - 59, -22); 45 break; 46 case 2: 47 btn_close.BackImg = btn_closeImg; 48 btn_close.Location = new Point(this.Width - 32, btnTop); 49 btn_max.BackImg = btn_maxImg; 50 btn_max.Location = new Point(this.Width - 59, -22); 51 btn_mini.BackImg = btn_miniImg; 52 btn_mini.Location = new Point(this.Width - 86, -22); 53 btn_restore.BackImg = btn_restoreImg; 54 btn_restore.Location = new Point(this.Width - 59, -22); 55 break; 56 case 3: 57 btn_close.BackImg = btn_closeImg; 58 btn_close.Location = new Point(this.Width - 32, btnTop); 59 btn_max.BackImg = btn_maxImg; 60 btn_max.Location = new Point(this.Width - 59, -22); 61 btn_mini.BackImg = btn_miniImg; 62 btn_mini.Location = new Point(this.Width - 59, 0); 63 btn_restore.BackImg = btn_restoreImg; 64 btn_restore.Location = new Point(this.Width - 59, -22); 65 break; 66 case 4: 67 btn_close.BackImg = btn_closeImg; 68 btn_close.Location = new Point(this.Width - 32, btnTop); 69 btn_mini.BackImg = btn_miniImg; 70 btn_mini.Location = new Point(this.Width - 86, -22); 71 btn_max.BackImg = btn_maxImg; 72 btn_restore.BackImg = btn_restoreImg; 73 if (WindowState == FormWindowState.Normal) 74 { 75 btn_max.Location = new Point(this.Width - 59, btnTop); 76 btn_restore.Location = new Point(this.Width - 59, -22); 77 } 78 else 79 { 80 btn_max.Location = new Point(this.Width - 59, -22); 81 btn_restore.Location = new Point(this.Width - 59, btnTop); 82 } 83 break; 84 } 85 } 86 87 private void WM_NCHITTEST(ref Message m) 88 { 89 int wparam = m.LParam.ToInt32(); 90 Point point = new Point(Win32.LOWORD(wparam), Win32.HIWORD(wparam)); 91 point = PointToClient(point); 92 if (_IsResize) 93 { 94 if (point.X <= 8) 95 { 96 if (point.Y <= 8) m.Result = (IntPtr)Win32.HTTOPLEFT; else if (point.Y > Height - 8) 97 m.Result = (IntPtr)Win32.HTBOTTOMLEFT; 98 else 99 m.Result = (IntPtr)Win32.HTLEFT; 100 } 101 else if (point.X >= Width - 8) 102 { 103 if (point.Y <= 8) m.Result = (IntPtr)Win32.HTTOPRIGHT; else if (point.Y >= Height - 8) 104 m.Result = (IntPtr)Win32.HTBOTTOMRIGHT; 105 else 106 m.Result = (IntPtr)Win32.HTRIGHT; 107 } 108 else if (point.Y <= 8) { m.Result = (IntPtr)Win32.HTTOP; } else if (point.Y >= Height - 8) 109 m.Result = (IntPtr)Win32.HTBOTTOM; 110 else 111 m.Result = (IntPtr)Win32.HTCAPTION; 112 } 113 else 114 { m.Result = (IntPtr)Win32.HTCAPTION; } 115 } 116 117 private void btn_close_Click(object sender, EventArgs e) 118 { 119 this.Close(); 120 } 121 122 private void btn_mini_Click(object sender, EventArgs e) 123 { 124 Win32.PostMessage(base.Handle, Win32.WM_SYSCOMMAND, Win32.SC_MINIMIZE, 0); 125 } 126 127 private void btn_max_Click(object sender, EventArgs e) 128 { 129 Win32.PostMessage(base.Handle, Win32.WM_SYSCOMMAND, Win32.SC_MAXIMIZE, 0); 130 } 131 132 private void btn_restore_Click(object sender, EventArgs e) 133 { 134 Win32.PostMessage(base.Handle, Win32.WM_SYSCOMMAND, Win32.SC_RESTORE, 0); 135 } 136 137 private void btn_close_MouseEnter(object sender, EventArgs e) 138 { 139 toolTip1.SetToolTip(btn_close, "關閉"); 140 } 141 142 private void btn_max_MouseEnter(object sender, EventArgs e) 143 { 144 toolTip1.SetToolTip(btn_max, "最大化"); 145 } 146 147 private void btn_mini_MouseEnter(object sender, EventArgs e) 148 { 149 toolTip1.SetToolTip(btn_mini, "最小化"); 150 } 151 152 private void btn_restore_MouseEnter(object sender, EventArgs e) 153 { 154 toolTip1.SetToolTip(btn_restore, "還原"); 155 } 156 #endregion
複製程式碼