IrregularForm.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //************************************************************************
  2. // https://github.com/yuzhengyang
  3. // author: yuzhengyang
  4. // date: 2017.4.27 - 2017.8.25
  5. // desc: 工具描述
  6. // Copyright (c) yuzhengyang. All rights reserved.
  7. //************************************************************************
  8. using System;
  9. using System.ComponentModel;
  10. using System.Drawing;
  11. using System.Threading;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. namespace Y.Skin.YoForm.Irregular
  15. {
  16. public partial class IrregularForm : Form
  17. {
  18. private IrregularFormSkin Skin;
  19. public Point MouseLocation { get { return Skin.MouseLocation; } }
  20. public IrregularForm()
  21. {
  22. InitializeComponent();
  23. //SetStyles();//减少闪烁
  24. ShowInTaskbar = false;//禁止控件层显示到任务栏
  25. FormBorderStyle = FormBorderStyle.None;//设置无边框的窗口样式
  26. TransparencyKey = BackColor;//使控件层背景透明
  27. }
  28. private void IrregularForm_Load(object sender, EventArgs e)
  29. {
  30. if (!DesignMode)
  31. {
  32. Skin = new IrregularFormSkin(this);//创建皮肤层
  33. BackgroundImage = null;//去除控件层背景
  34. Skin.Show();//显示皮肤层
  35. //设置右键菜单
  36. if (ContextMenuStrip != null) Skin.ContextMenuStrip = ContextMenuStrip;
  37. }
  38. }
  39. #region 属性
  40. private bool _Moveable = true;
  41. [Category("Skin")]
  42. [Description("窗体是否可以移动")]
  43. [DefaultValue(typeof(bool), "true")]
  44. public bool Movable
  45. {
  46. get { return _Moveable; }
  47. set
  48. {
  49. if (_Moveable != value)
  50. {
  51. _Moveable = value;
  52. }
  53. }
  54. }
  55. private bool _InTaskbar = true;
  56. [Category("Skin")]
  57. [Description("窗体是否显示到任务栏")]
  58. [DefaultValue(typeof(bool), "true")]
  59. public bool InTaskbar
  60. {
  61. get { return _InTaskbar; }
  62. set
  63. {
  64. if (_InTaskbar != value)
  65. {
  66. _InTaskbar = value;
  67. }
  68. }
  69. }
  70. #endregion
  71. #region 减少闪烁
  72. private void SetStyles()
  73. {
  74. SetStyle(
  75. ControlStyles.UserPaint |
  76. ControlStyles.AllPaintingInWmPaint |
  77. ControlStyles.OptimizedDoubleBuffer |
  78. ControlStyles.ResizeRedraw |
  79. ControlStyles.DoubleBuffer, true);
  80. //强制分配样式重新应用到控件上
  81. UpdateStyles();
  82. base.AutoScaleMode = AutoScaleMode.None;
  83. }
  84. #endregion
  85. /// <summary>
  86. /// 窗体显示状态
  87. /// </summary>
  88. /// <param name="value"></param>
  89. public void Visibility(bool value)
  90. {
  91. if (value)
  92. {
  93. Show();
  94. Skin.Show();
  95. }
  96. else
  97. {
  98. Hide();
  99. Skin.Hide();
  100. }
  101. }
  102. public void SetBackground(Image img)
  103. {
  104. Skin.BackgroundImage = img;
  105. Skin.SetBits();
  106. }
  107. }
  108. }