123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using LYFZ.WinAPI;
- namespace LYFZ.ComponentLibrary
- {
- /// <summary>
- /// 无边框四边阴影基窗体
- /// </summary>
- public partial class BaseShadowForm : BaseMotherForm
- {
- ShadowLayer layer = null;
- bool _isShadow = true;
- /// <summary>
- /// 是否开启四边阴影
- /// </summary>
- [DescriptionAttribute("是否开启四边阴影"), CategoryAttribute("自定义窗体属性"), DefaultValueAttribute(typeof(bool), "true")]
- public bool IsShadow
- {
- get { return _isShadow; }
- set { _isShadow = value; }
- }
- Rectangle _layerRel = new Rectangle(5,5,10,12);
- /// <summary>
- /// 在开启阴影效果时设置阴影位置和大小
- /// </summary>
- [DescriptionAttribute("在开启阴影效果时设置阴影位置和大小"), CategoryAttribute("自定义窗体属性")]
- public Rectangle LayerRel
- {
- get { return _layerRel; }
- set { _layerRel = value; }
- }
- public BaseShadowForm()
- {
- InitializeComponent();
- }
- //Show或Hide被调用时
- protected override void OnVisibleChanged(EventArgs e)
- {
- if (Visible)
- {
- //启用窗口淡入淡出
- if (!DesignMode)
- {
- //淡入特效
- // Win32.AnimateWindow(this.Handle, 150, Win32.AW_BLEND | Win32.AW_ACTIVATE);
- }
- //判断不是在设计器中
- if (!DesignMode && (layer == null ||layer.IsDisposed))
- {
- if (IsShadow)
- {
- layer = new ShadowLayer(this);
- layer.Difference_X = LayerRel.X;
- layer.Difference_Y = LayerRel.Y;
- layer.Difference_Width = LayerRel.Width;
- layer.Difference_Height = LayerRel.Height;
- if (this.IsReion && this.Width == 780 && this.Height == 580)
- {
- layer.Difference_X = 19;
- layer.Difference_Y = 27;
- layer.Difference_Width = 38;
- layer.Difference_Height = 46;
- layer.SetInit();
- }
- try
- {
- layer.Show(this);
- }
- catch { }
- }
- }
- base.OnVisibleChanged(e);
- }
- else
- {
- base.OnVisibleChanged(e);
- // Win32.AnimateWindow(this.Handle, 150, Win32.AW_BLEND | Win32.AW_HIDE);
- }
- }
- //窗体关闭时
- protected override void OnClosing(CancelEventArgs e)
- {
- base.OnClosing(e);
- try
- {
- //先关闭阴影窗体
- if (layer != null && !layer.IsDisposed)
- {
- layer.Close();
- layer.Dispose();
- layer = null;
- }
- }
- catch { }
- //在Form_FormClosing中添加代码实现窗体的淡出
- // Win32.AnimateWindow(this.Handle, 150, Win32.AW_BLEND | Win32.AW_HIDE);
- }
- }
- }
|