IrregularForm.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //############################################################
  2. // https://github.com/yuzhengyang
  3. // author:yuzhengyang
  4. //############################################################
  5. using System;
  6. using System.ComponentModel;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace Y.Skin.YoForm.Irregular
  11. {
  12. public partial class IrregularForm : Form
  13. {
  14. private IrregularFormSkin Skin;
  15. public IrregularForm()
  16. {
  17. InitializeComponent();
  18. //SetStyles();//减少闪烁
  19. ShowInTaskbar = false;//禁止控件层显示到任务栏
  20. FormBorderStyle = FormBorderStyle.None;//设置无边框的窗口样式
  21. TransparencyKey = BackColor;//使控件层背景透明
  22. }
  23. private void IrregularForm_Load(object sender, EventArgs e)
  24. {
  25. if (!DesignMode)
  26. {
  27. Opacity = 0;
  28. Skin = new IrregularFormSkin(this);//创建皮肤层
  29. BackgroundImage = null;//去除控件层背景
  30. Skin.Show();//显示皮肤层
  31. AnimateShow();
  32. }
  33. }
  34. #region 属性
  35. private bool _skinmobile = true;
  36. [Category("Skin")]
  37. [Description("窗体是否可以移动")]
  38. [DefaultValue(typeof(bool), "true")]
  39. public bool SkinMovable
  40. {
  41. get { return _skinmobile; }
  42. set
  43. {
  44. if (_skinmobile != value)
  45. {
  46. _skinmobile = value;
  47. }
  48. }
  49. }
  50. #endregion
  51. #region 减少闪烁
  52. private void SetStyles()
  53. {
  54. SetStyle(
  55. ControlStyles.UserPaint |
  56. ControlStyles.AllPaintingInWmPaint |
  57. ControlStyles.OptimizedDoubleBuffer |
  58. ControlStyles.ResizeRedraw |
  59. ControlStyles.DoubleBuffer, true);
  60. //强制分配样式重新应用到控件上
  61. UpdateStyles();
  62. base.AutoScaleMode = AutoScaleMode.None;
  63. }
  64. #endregion
  65. private void AnimateShow()
  66. {
  67. Task.Factory.StartNew(() =>
  68. {
  69. for (int i = 0; i <= 10; i++)
  70. {
  71. BeginInvoke(new Action(() =>
  72. {
  73. Opacity = i / 10.0;
  74. Skin.SetBits();
  75. }));
  76. Thread.Sleep(25);
  77. }
  78. });
  79. }
  80. }
  81. }