IrregularForm.cs 2.4 KB

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