码迷,mamicode.com
首页 > Windows程序 > 详细

WinForm显示关闭窗体特效封装

时间:2018-02-25 15:52:39      阅读:335      评论:0      收藏:0      [点我收藏+]

标签:art   app   拉伸   struct   new   windows   gpo   using   nfa   

1.代码结构截图

技术分享图片

2.核心代码
using System;
using System.Drawing;
using System.Windows.Forms;

namespace AnimationForm
{
    /// <summary>
    ///     WinForm常用的几种显示特效
    ///     LDH @ 2018-2-25
    /// </summary>
    public partial class FrmMain : Form
    {
        #region Constructor

        public FrmMain()
        {
            InitializeComponent();
        }

        #endregion

        #region Form Events

        /// <summary>
        ///     窗体加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmMain_Load(object sender, EventArgs e)
        {
            Win32EffectHelper.ExpandEffect(this);
        }


        /// <summary>
        ///     从左到右特效
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void winBtnLeftToRight_Click(object sender, EventArgs e)
        {
            Win32EffectHelper.LeftToRightEffect(this);
        }

        /// <summary>
        ///     从右到左特效
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void winBtnRightToLeft_Click(object sender, EventArgs e)
        {
            Win32EffectHelper.RightToLeftEffect(this);
        }

        /// <summary>
        ///     从上到下特效
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void winBtnTopToBottom_Click(object sender, EventArgs e)
        {
            Win32EffectHelper.TopToBottom(this);
        }

        /// <summary>
        ///     从下到上特效
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void winBtnBottomToTop_Click(object sender, EventArgs e)
        {
            Win32EffectHelper.BottomToTop(this);
        }

        /// <summary>
        ///     渐变特效
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void winBtnGradualChange_Click(object sender, EventArgs e)
        {
            Win32EffectHelper.FadeInFadeOutEffect(this);
        }

        /// <summary>
        ///     收缩扩张特效
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void winBtnExpand_Click(object sender, EventArgs e)
        {
            Win32EffectHelper.ShrinkEffect(this);
        }

        /// <summary>
        ///     退出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void exitEToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Win32EffectHelper.Outer2MiddleDisappear(this);
        }

        /// <summary>
        ///     右下角显示窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void winBtnShowFormInRightCorner_Click(object sender, EventArgs e)
        {
            Win32EffectHelper.ShowFormInRightBottomCorner(this);
        }

        /// <summary>
        ///     从上到下 伸缩后消失
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void winBtnTop2BottomDisappear_Click(object sender, EventArgs e)
        {
            Win32EffectHelper.Top2BottomDisappear(this);
        }

        /// <summary>
        ///     从下到上  伸缩后消失
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void winBtnBottom2TopDisappear_Click(object sender, EventArgs e)
        {
            Win32EffectHelper.Bottom2TopDisappear(this);
        }

        /// <summary>
        ///     从左到右  伸缩后消失
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void winBtnLeft2RightDisappear_Click(object sender, EventArgs e)
        {
            Win32EffectHelper.Left2RightDisappear(this);
        }

        /// <summary>
        ///     从右到左  伸缩后消失
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void winBtnRight2LeftDisappear_Click(object sender, EventArgs e)
        {
            Win32EffectHelper.Right2LeftDisappear(this);
        }

        /// <summary>
        ///     四周向中间 缩小后消失
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void winBtnOuter2MiddleDisappear_Click(object sender, EventArgs e)
        {
            Win32EffectHelper.Outer2MiddleDisappear(this);
        }

        /// <summary>
        ///     关闭窗体事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            Win32EffectHelper.Outer2MiddleDisappear(this);
        }

        #endregion

        #region 控制改变窗体拉伸和移动

        private const int HTLEFT = 10;
        private const int HTRIGHT = 11;
        private const int HTTOP = 12;
        private const int HTTOPLEFT = 13;
        private const int HTTOPRIGHT = 14;
        private const int HTBOTTOM = 15;
        private const int HTBOTTOMLEFT = 0x10;
        private const int HTBOTTOMRIGHT = 17;

        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case 0x0084:
                    base.WndProc(ref m);
                    var vPoint = new Point((int) m.LParam & 0xFFFF, ((int) m.LParam >> 16) & 0xFFFF);
                    vPoint = PointToClient(vPoint);

                    if (vPoint.X <= 5)
                    {
                        if (vPoint.Y <= 5)
                        {
                            m.Result = (IntPtr) HTTOPLEFT;
                        }
                        else if (vPoint.Y >= ClientSize.Height - 5)
                        {
                            m.Result = (IntPtr) HTBOTTOMLEFT;
                        }
                        else
                        {
                            m.Result = (IntPtr) HTLEFT;
                        }
                    }
                    else if (vPoint.X >= ClientSize.Width - 5)
                    {
                        if (vPoint.Y <= 5)
                        {
                            m.Result = (IntPtr) HTTOPRIGHT;
                        }
                        else if (vPoint.Y >= ClientSize.Height - 5)
                        {
                            m.Result = (IntPtr) HTBOTTOMRIGHT;
                        }
                        else
                        {
                            m.Result = (IntPtr) HTRIGHT;
                        }
                    }
                    else if (vPoint.Y <= 5)
                    {
                        m.Result = (IntPtr) HTTOP;
                    }
                    else if (vPoint.Y >= ClientSize.Height - 5)
                    {
                        m.Result = (IntPtr) HTBOTTOM;
                    }
                    break;

                case 0x0201: //鼠标左键按下的消息 
                    m.Msg = 0x00A1; //更改消息为非客户区按下鼠标 
                    m.LParam = IntPtr.Zero; //默认值 
                    m.WParam = new IntPtr(2); //鼠标放在标题栏内 
                    base.WndProc(ref m);
                    break;

                default:
                    base.WndProc(ref m);
                    break;
            }
        }

        #endregion
    }
}
3.效果录像

技术分享图片

WinForm显示关闭窗体特效封装

标签:art   app   拉伸   struct   new   windows   gpo   using   nfa   

原文地址:https://www.cnblogs.com/LifeDecidesHappiness/p/8469393.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!