TestShadowForm.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Runtime.InteropServices;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using Y.Utils.WindowsUtils.APIUtils;
  11. namespace Y.Test.Views
  12. {
  13. public partial class TestShadowForm : Form
  14. {
  15. private Point _MouseLocation;
  16. internal Point MouseLocation { get { return _MouseLocation; } }
  17. int ShadowWidth = 0;
  18. private Form Shadow;
  19. public TestShadowForm()
  20. {
  21. InitializeComponent();
  22. FormBorderStyle = FormBorderStyle.None;//设置无边框的窗口样式
  23. //Opacity = 0.5;
  24. }
  25. private void TestShadowForm_Load(object sender, EventArgs e)
  26. {
  27. if (!DesignMode)
  28. {
  29. Shadow = new Form();//创建皮肤层
  30. Owner = Shadow;//设置控件层的拥有皮肤层
  31. Shadow.ShowInTaskbar = false;//禁止阴影显示到任务栏
  32. Shadow.Size = Size;//统一大小
  33. ShadowWidth = (Shadow.Width - 2 - Shadow.ClientRectangle.Width) / 2;
  34. Shadow.Width += ShadowWidth * 2;
  35. Shadow.Height += ShadowWidth;
  36. TestShadowForm_LocationChanged(this, null);
  37. Shadow.Show();//显示皮肤层
  38. }
  39. }
  40. #region 属性
  41. private bool _Moveable = true;
  42. [Category("Skin")]
  43. [Description("窗体是否可以移动")]
  44. [DefaultValue(typeof(bool), "true")]
  45. public bool Movable
  46. {
  47. get { return _Moveable; }
  48. set
  49. {
  50. if (_Moveable != value)
  51. {
  52. _Moveable = value;
  53. }
  54. }
  55. }
  56. private bool _InTaskbar = true;
  57. [Category("Skin")]
  58. [Description("窗体是否显示到任务栏")]
  59. [DefaultValue(typeof(bool), "true")]
  60. public bool InTaskbar
  61. {
  62. get { return _InTaskbar; }
  63. set
  64. {
  65. if (_InTaskbar != value)
  66. {
  67. _InTaskbar = value;
  68. }
  69. }
  70. }
  71. #endregion
  72. /// <summary>
  73. /// 窗体显示状态
  74. /// </summary>
  75. /// <param name="value"></param>
  76. public void Visibility(bool value)
  77. {
  78. if (value)
  79. {
  80. Show();
  81. Shadow.Show();
  82. }
  83. else
  84. {
  85. Hide();
  86. Shadow.Hide();
  87. }
  88. }
  89. protected override void OnMouseMove(MouseEventArgs e)
  90. {
  91. base.OnMouseMove(e);
  92. _MouseLocation = e.Location;
  93. if (e.Button == MouseButtons.Left)
  94. {
  95. FormStyleAPI.ReleaseCapture();
  96. FormStyleAPI.SendMessage(Handle, FormStyleAPI.WM_NCLBUTTONDOWN, FormStyleAPI.HTCAPTION, 0);
  97. }
  98. }
  99. private void TestShadowForm_LocationChanged(object sender, EventArgs e)
  100. {
  101. if (Shadow != null)
  102. {
  103. Shadow.Location = new Point(Left - ShadowWidth, Top);
  104. }
  105. }
  106. }
  107. }