IrregularForm.cs 3.2 KB

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