You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
3.6 KiB

  1. #if NETFX || NETCORE
  2. using Apewer.Internals.Interop;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Drawing;
  7. using System.Drawing.Drawing2D;
  8. using System.Windows.Forms;
  9. namespace Apewer.Surface
  10. {
  11. /// <summary>
  12. ///
  13. /// </summary>
  14. public class BlockForm : BaseForm
  15. {
  16. #region this
  17. private bool _haveshadow = false;
  18. /// <summary></summary>
  19. public BlockForm()
  20. {
  21. Optimize();
  22. }
  23. /// <summary>包含窗体阴影。</summary>
  24. public bool HaveShadow
  25. {
  26. get { return _haveshadow; }
  27. set
  28. {
  29. _haveshadow = value;
  30. if (value) { if (_shadow != null) HideShadow(); }
  31. else { if (_shadow == null) ShowShadow(); }
  32. }
  33. }
  34. #endregion
  35. #region override
  36. /// <summary>显示或隐藏时的动画和阴影。</summary>
  37. protected override void OnVisibleChanged(EventArgs e)
  38. {
  39. if (Visible)
  40. {
  41. if (!DesignMode) User32.AnimateWindow(this.Handle, 150, Constant.AW_BLEND | Constant.AW_ACTIVATE);
  42. if (!DesignMode && _shadow == null) ShowShadow();
  43. base.OnVisibleChanged(e);
  44. }
  45. else
  46. {
  47. base.OnVisibleChanged(e);
  48. User32.AnimateWindow(this.Handle, 150, Constant.AW_BLEND | Constant.AW_HIDE);
  49. }
  50. }
  51. /// <summary>关闭窗体时同时关闭阴影。</summary>
  52. protected override void OnClosing(CancelEventArgs e)
  53. {
  54. HideShadow();
  55. base.OnClosing(e);
  56. User32.AnimateWindow(this.Handle, 150, Constant.AW_BLEND | Constant.AW_HIDE);
  57. }
  58. #endregion
  59. #region surface
  60. /// <summary>
  61. ///
  62. /// </summary>
  63. /// <param name="color"></param>
  64. /// <param name="titleHeight"></param>
  65. /// <param name="border"></param>
  66. public void PaintWall(Color color, int titleHeight, bool border = true)
  67. {
  68. var bitmap = new Bitmap(Width, Height);
  69. var graphic = Graphics.FromImage(bitmap);
  70. var brush = new SolidBrush(color);
  71. var pen = new Pen(color);
  72. graphic.FillRectangle(brush, 0, 0, Width, titleHeight);
  73. if (border) graphic.DrawRectangle(pen, 0, 0, Width - 1, Height - 1);
  74. pen.Dispose();
  75. brush.Dispose();
  76. graphic.Dispose();
  77. if (BackgroundImage != null) BackgroundImage.Dispose();
  78. BackgroundImage = bitmap;
  79. }
  80. #endregion
  81. #region shadow
  82. /// <summary>窗体阴影边框。</summary>
  83. private BlockShadow _shadow;
  84. private void ShowShadow()
  85. {
  86. if (!HaveShadow) return;
  87. _shadow = new BlockShadow(this);
  88. _shadow.Show(this);
  89. }
  90. private void HideShadow()
  91. {
  92. if (_shadow != null)
  93. {
  94. _shadow.Close();
  95. _shadow.Dispose();
  96. _shadow = null;
  97. }
  98. }
  99. /// <summary>阴影已溢出屏幕。</summary>
  100. public bool ShadowOverflow
  101. {
  102. get
  103. {
  104. int vwidth = Width + 200;
  105. int vheight = Height + 200;
  106. if ((vwidth > Screen.PrimaryScreen.Bounds.Width) || (vheight > Screen.PrimaryScreen.Bounds.Height))
  107. {
  108. return true;
  109. }
  110. else return false;
  111. }
  112. }
  113. #endregion
  114. }
  115. }
  116. #endif