private void AnimateWindow(bool show)
{
if (!this.FlagAnimate && Visible != show)
{
Visible = show;
return;
}
Parent.SuspendLayout();
Rectangle rectSource = this.GetRectangle(!show);
Rectangle rectTarget = this.GetRectangle(show);
int dxLoc, dyLoc;
int dWidth, dHeight;
dxLoc = dyLoc = dWidth = dHeight = 0;
if (this.DockState == DockState.DockTopAutoHide)
dHeight = show ? 1 : -1;
else if (this.DockState == DockState.DockLeftAutoHide)
dWidth = show ? 1 : -1;
else if (this.DockState == DockState.DockRightAutoHide)
{
dxLoc = show ? -1 : 1;
dWidth = show ? 1 : -1;
}
else if (this.DockState == DockState.DockBottomAutoHide)
{
dyLoc = (show ? -1 : 1);
dHeight = (show ? 1 : -1);
}
if (show)
{
Bounds = this.DockPanel.GetAutoHideWindowBounds(new Rectangle(-rectTarget.Width, -rectTarget.Height, rectTarget.Width, rectTarget.Height));
if (Visible == false)
Visible = true;
PerformLayout();
}
SuspendLayout();
this.LayoutAnimateWindow(rectSource);
if (Visible == false)
Visible = true;
int speedFactor = 1;
int totalPixels = (rectSource.Width != rectTarget.Width) ?
Math.Abs(rectSource.Width - rectTarget.Width) :
Math.Abs(rectSource.Height - rectTarget.Height);
int remainPixels = totalPixels;
DateTime startingTime = DateTime.Now;
while (rectSource != rectTarget)
{
DateTime startPerMove = DateTime.Now;
rectSource.X += dxLoc * speedFactor;
rectSource.Y += dyLoc * speedFactor;
rectSource.Width += dWidth * speedFactor;
rectSource.Height += dHeight * speedFactor;
if (Math.Sign(rectTarget.X - rectSource.X) != Math.Sign(dxLoc))
rectSource.X = rectTarget.X;
if (Math.Sign(rectTarget.Y - rectSource.Y) != Math.Sign(dyLoc))
rectSource.Y = rectTarget.Y;
if (Math.Sign(rectTarget.Width - rectSource.Width) != Math.Sign(dWidth))
rectSource.Width = rectTarget.Width;
if (Math.Sign(rectTarget.Height - rectSource.Height) != Math.Sign(dHeight))
rectSource.Height = rectTarget.Height;
this.LayoutAnimateWindow(rectSource);
if (Parent != null)
Parent.Update();
remainPixels -= speedFactor;
while (true)
{
var time = new TimeSpan(0, 0, 0, 0, ANIMATE_TIME);
TimeSpan elapsedPerMove = DateTime.Now - startPerMove;
TimeSpan elapsedTime = DateTime.Now - startingTime;
if (((int)((time - elapsedTime).TotalMilliseconds)) <= 0)
{
speedFactor = remainPixels;
break;
}
else
speedFactor = remainPixels * (int)elapsedPerMove.TotalMilliseconds / (int)((time - elapsedTime).TotalMilliseconds);
if (speedFactor >= 1)
break;
}
}
ResumeLayout();
Parent.ResumeLayout();
}