skinform.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Security.Permissions;
  9. namespace US.Browser.IE
  10. {
  11. /// <summary>
  12. /// 无边框窗体使用区域
  13. /// </summary>
  14. [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
  15. [System.Runtime.InteropServices.ComVisibleAttribute(true)]
  16. public partial class skinform : Form
  17. {
  18. skinm _usk;
  19. const int WM_ERASEBKGND = 0x14;
  20. const int WS_MINIMIZEBOX = 0x00020000;
  21. const int CS_DROPSHADOW = 0x20000;
  22. /// <summary>
  23. /// 初始化
  24. /// </summary>
  25. public skinform()
  26. {
  27. InitializeComponent(); SetStyles();
  28. }
  29. /// <summary>
  30. /// 画上阴影边框
  31. /// </summary>
  32. /// <param name="sender"></param>
  33. /// <param name="e"></param>
  34. void skinform_Paint(object sender, PaintEventArgs e)
  35. {
  36. Rectangle myRectangle = new Rectangle(0, 0, this.Width, this.Height);
  37. ControlPaint.DrawBorder(e.Graphics, myRectangle, Color.FromArgb(80, 80, 80), 5, ButtonBorderStyle.Solid, Color.FromArgb(80, 80, 80), 5, ButtonBorderStyle.Solid, Color.FromArgb(80, 80, 80), 5, ButtonBorderStyle.Solid, Color.FromArgb(80, 80, 80), 5, ButtonBorderStyle.Solid);
  38. }
  39. #region
  40. /// <summary>
  41. /// 窗体大小变化
  42. /// </summary>
  43. /// <param name="e"></param>
  44. protected override void OnSizeChanged(EventArgs e)
  45. {
  46. base.OnSizeChanged(e);
  47. BLL.WindowHWND.SetFormRoundRectRgn(this, this.WindowState == FormWindowState.Maximized ? 0 : 15);
  48. }
  49. #endregion
  50. #region 窗体美化
  51. #region 设置样式
  52. /// <summary>
  53. /// 添加控件信息
  54. /// </summary>
  55. protected override CreateParams CreateParams
  56. {
  57. get
  58. {
  59. CreateParams cp = base.CreateParams;
  60. cp.Style |= WM_ERASEBKGND | WS_MINIMIZEBOX;
  61. cp.ClassStyle |= CS_DROPSHADOW;
  62. return cp;
  63. }
  64. }
  65. /// <summary>
  66. /// 设置样式
  67. /// </summary>
  68. private void SetStyles()
  69. {
  70. SetStyle(ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.DoubleBuffer, true); //自行绘制 禁止擦除背景 缓存
  71. UpdateStyles(); base.AutoScaleMode = AutoScaleMode.None;
  72. }
  73. #endregion
  74. /// <summary>
  75. /// 显示影藏变化
  76. /// </summary>
  77. /// <param name="e"></param>
  78. protected override void OnVisibleChanged(EventArgs e)
  79. {
  80. if (Visible)
  81. {
  82. if (!DesignMode)
  83. {
  84. BLL.WindowHWND.AnimateWindow(this.Handle, 100, BLL.WindowHWND.AW_BLEND | BLL.WindowHWND.AW_ACTIVATE); //淡入淡出
  85. if (_usk == null) //添加绘图窗体层
  86. {
  87. // _usk = new skinm(this, new Point(this.Location.X - 5, this.Location.Y - 5));
  88. // _usk.Show(this);
  89. }
  90. }
  91. }
  92. else { BLL.WindowHWND.AnimateWindow(this.Handle, 100, BLL.WindowHWND.AW_BLEND | BLL.WindowHWND.AW_HIDE); }//淡入淡出
  93. base.OnVisibleChanged(e); SetStyles(); this.Refresh();
  94. }
  95. /// <summary>
  96. /// 窗体关闭
  97. /// </summary>
  98. /// <param name="e"></param>
  99. protected override void OnClosing(CancelEventArgs e)
  100. {
  101. base.OnClosing(e); if (_usk != null) { _usk.Close(); }
  102. BLL.WindowHWND.AnimateWindow(this.Handle, 150, BLL.WindowHWND.AW_BLEND | BLL.WindowHWND.AW_HIDE);
  103. }
  104. #region 拉伸
  105. const int WM_NCHITTEST = 0x0084;
  106. const int HT_LEFT = 10;
  107. const int HT_RIGHT = 11;
  108. const int HT_TOP = 12;
  109. const int HT_TOPLEFT = 13;
  110. const int HT_TOPRIGHT = 14;
  111. const int HT_BOTTOM = 15;
  112. const int HT_BOTTOMLEFT = 16;
  113. const int HT_BOTTOMRIGHT = 17;
  114. const int HT_CAPTION = 2;
  115. const Int32 WM_PARENTNOTIFY = 0x210;
  116. const Int32 WM_DESTROY = 0x2;
  117. #endregion
  118. #region 钩子
  119. /// <summary>
  120. /// 窗口轮子
  121. /// </summary>
  122. /// <param name="Msg"></param>
  123. protected override void WndProc(ref Message Msg)
  124. {
  125. switch (Msg.Msg)
  126. {
  127. case WM_ERASEBKGND: Msg.Result = IntPtr.Zero; break;
  128. }
  129. if (Msg.Msg == WM_NCHITTEST)
  130. {
  131. //获取鼠标位置
  132. int nPosX = (Msg.LParam.ToInt32() & 65535);
  133. int nPosY = (Msg.LParam.ToInt32() >> 16);
  134. //右下角
  135. if (nPosX >= this.Right - 6 && nPosY >= this.Bottom - 6)
  136. {
  137. Msg.Result = new IntPtr(HT_BOTTOMRIGHT);
  138. return;
  139. }
  140. //左上角
  141. else if (nPosX <= this.Left + 6 && nPosY <= this.Top + 6)
  142. {
  143. Msg.Result = new IntPtr(HT_TOPLEFT);
  144. return;
  145. }
  146. //左下角
  147. else if (nPosX <= this.Left + 6 && nPosY >= this.Bottom - 6)
  148. {
  149. Msg.Result = new IntPtr(HT_BOTTOMLEFT);
  150. return;
  151. }
  152. //右上角
  153. else if (nPosX >= this.Right - 6 && nPosY <= this.Top + 6)
  154. {
  155. Msg.Result = new IntPtr(HT_TOPRIGHT);
  156. return;
  157. }
  158. else if (nPosX >= this.Right - 2)
  159. {
  160. Msg.Result = new IntPtr(HT_RIGHT);
  161. return;
  162. }
  163. else if (nPosY >= this.Bottom - 2)
  164. {
  165. Msg.Result = new IntPtr(HT_BOTTOM);
  166. return;
  167. }
  168. else if (nPosX <= this.Left + 2)
  169. {
  170. Msg.Result = new IntPtr(HT_LEFT);
  171. return;
  172. }
  173. else if (nPosY <= this.Top + 2)
  174. {
  175. Msg.Result = new IntPtr(HT_TOP);
  176. return;
  177. }
  178. else
  179. {
  180. Msg.Result = new IntPtr(HT_CAPTION);
  181. return;
  182. }
  183. }
  184. base.WndProc(ref Msg);
  185. }
  186. #endregion
  187. #endregion
  188. }
  189. }