#if NETFX || NETCORE using Apewer.Internals.Interop; using System; using System.Collections.Generic; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Apewer.Surface { /// 由 .NET Framework 提供的标准窗体。 public class NormalForm : System.Windows.Forms.Form { /// 必需的设计器变量。 private System.ComponentModel.IContainer components = null; /// 清理所有正在使用的资源。 /// 如果应释放托管资源,为 true;否则为 false。 protected override void Dispose(bool disposing) { if (disposing && (components != null)) components.Dispose(); base.Dispose(disposing); } #region Windows 窗体设计器生成的代码 /// /// 设计器支持所需的方法 - 不要修改 /// 使用代码编辑器修改此方法的内容。 /// private void InitializeComponent() { this.SuspendLayout(); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.ClientSize = new System.Drawing.Size(900, 600); this.Font = FormsUtility.DefaultFont; this.Text = "NormalForm"; this.ResumeLayout(false); } #endregion /// 构造函数。 public NormalForm() { InitializeComponent(); } /// 获取 DPI 缩放比例。 public double DpiScale { get { if (FormsUtility.DpiScale == null) { using (var g = CreateGraphics()) { FormsUtility.DpiScale = g.DpiX / 96F; } } return FormsUtility.DpiScale.Value; } } /// /// /// /// protected override void WndProc(ref Message m) { // WM_DPICHANGED = 0x02E0 base.WndProc(ref m); } #region Aero private bool AeroEnabled = false; /// 启用 Aero 透明效果。 private void EnableAero() { AeroEnabled = true; Load += (s, e) => { if (!FormsUtility.DwmIsCompositionEnabled) return; var width = Width; var height = Height; var margins = new MARGINS(); // margins.Right = -1; // 全窗体透明。 margins.Right = margins.Left = margins.Top = margins.Bottom = width + height; DwmApi.DwmExtendFrameIntoClientArea(Handle, ref margins); }; } /// protected override void OnPaintBackground(PaintEventArgs e) { base.OnPaintBackground(e); if (AeroEnabled) { if (FormsUtility.DwmIsCompositionEnabled) { e.Graphics.Clear(Color.Black); } } } #endregion } } #endif