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.

120 lines
3.3 KiB

  1. #if NETFX || NETCORE
  2. using Apewer.Internals.Interop;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. namespace Apewer.Surface
  9. {
  10. /// <summary>由 .NET Framework 提供的标准窗体。</summary>
  11. public class NormalForm : System.Windows.Forms.Form
  12. {
  13. /// <summary>必需的设计器变量。</summary>
  14. private System.ComponentModel.IContainer components = null;
  15. /// <summary>清理所有正在使用的资源。</summary>
  16. /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
  17. protected override void Dispose(bool disposing)
  18. {
  19. if (disposing && (components != null)) components.Dispose();
  20. base.Dispose(disposing);
  21. }
  22. #region Windows 窗体设计器生成的代码
  23. /// <summary>
  24. /// 设计器支持所需的方法 - 不要修改
  25. /// 使用代码编辑器修改此方法的内容。
  26. /// </summary>
  27. private void InitializeComponent()
  28. {
  29. this.SuspendLayout();
  30. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
  31. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  32. this.ClientSize = new System.Drawing.Size(900, 600);
  33. this.Font = FormsUtility.DefaultFont;
  34. this.Text = "NormalForm";
  35. this.ResumeLayout(false);
  36. }
  37. #endregion
  38. /// <summary>构造函数。</summary>
  39. public NormalForm()
  40. {
  41. InitializeComponent();
  42. }
  43. /// <summary>获取 DPI 缩放比例。</summary>
  44. public double DpiScale
  45. {
  46. get
  47. {
  48. if (FormsUtility.DpiScale == null)
  49. {
  50. using (var g = CreateGraphics())
  51. {
  52. FormsUtility.DpiScale = g.DpiX / 96F;
  53. }
  54. }
  55. return FormsUtility.DpiScale.Value;
  56. }
  57. }
  58. /// <summary>
  59. ///
  60. /// </summary>
  61. /// <param name="m"></param>
  62. protected override void WndProc(ref Message m)
  63. {
  64. // WM_DPICHANGED = 0x02E0
  65. base.WndProc(ref m);
  66. }
  67. #region Aero
  68. private bool AeroEnabled = false;
  69. /// <summary>启用 Aero 透明效果。</summary>
  70. private void EnableAero()
  71. {
  72. AeroEnabled = true;
  73. Load += (s, e) =>
  74. {
  75. if (!FormsUtility.DwmIsCompositionEnabled) return;
  76. var width = Width;
  77. var height = Height;
  78. var margins = new MARGINS();
  79. // margins.Right = -1; // 全窗体透明。
  80. margins.Right = margins.Left = margins.Top = margins.Bottom = width + height;
  81. DwmApi.DwmExtendFrameIntoClientArea(Handle, ref margins);
  82. };
  83. }
  84. /// <summary></summary>
  85. protected override void OnPaintBackground(PaintEventArgs e)
  86. {
  87. base.OnPaintBackground(e);
  88. if (AeroEnabled)
  89. {
  90. if (FormsUtility.DwmIsCompositionEnabled)
  91. {
  92. e.Graphics.Clear(Color.Black);
  93. }
  94. }
  95. }
  96. #endregion
  97. }
  98. }
  99. #endif