#if NETFX || NETCORE using Apewer.Internals.Interop; using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; namespace Apewer.Surface { /// /// /// public class BlockForm : BaseForm { #region this private bool _haveshadow = false; /// public BlockForm() { Optimize(); } /// 包含窗体阴影。 public bool HaveShadow { get { return _haveshadow; } set { _haveshadow = value; if (value) { if (_shadow != null) HideShadow(); } else { if (_shadow == null) ShowShadow(); } } } #endregion #region override /// 显示或隐藏时的动画和阴影。 protected override void OnVisibleChanged(EventArgs e) { if (Visible) { if (!DesignMode) User32.AnimateWindow(this.Handle, 150, Constant.AW_BLEND | Constant.AW_ACTIVATE); if (!DesignMode && _shadow == null) ShowShadow(); base.OnVisibleChanged(e); } else { base.OnVisibleChanged(e); User32.AnimateWindow(this.Handle, 150, Constant.AW_BLEND | Constant.AW_HIDE); } } /// 关闭窗体时同时关闭阴影。 protected override void OnClosing(CancelEventArgs e) { HideShadow(); base.OnClosing(e); User32.AnimateWindow(this.Handle, 150, Constant.AW_BLEND | Constant.AW_HIDE); } #endregion #region surface /// /// /// /// /// /// public void PaintWall(Color color, int titleHeight, bool border = true) { var bitmap = new Bitmap(Width, Height); var graphic = Graphics.FromImage(bitmap); var brush = new SolidBrush(color); var pen = new Pen(color); graphic.FillRectangle(brush, 0, 0, Width, titleHeight); if (border) graphic.DrawRectangle(pen, 0, 0, Width - 1, Height - 1); pen.Dispose(); brush.Dispose(); graphic.Dispose(); if (BackgroundImage != null) BackgroundImage.Dispose(); BackgroundImage = bitmap; } #endregion #region shadow /// 窗体阴影边框。 private BlockShadow _shadow; private void ShowShadow() { if (!HaveShadow) return; _shadow = new BlockShadow(this); _shadow.Show(this); } private void HideShadow() { if (_shadow != null) { _shadow.Close(); _shadow.Dispose(); _shadow = null; } } /// 阴影已溢出屏幕。 public bool ShadowOverflow { get { int vwidth = Width + 200; int vheight = Height + 200; if ((vwidth > Screen.PrimaryScreen.Bounds.Width) || (vheight > Screen.PrimaryScreen.Bounds.Height)) { return true; } else return false; } } #endregion } } #endif