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
}
}