/// <summary> /// Sets up the animation for resizing the window /// </summary> /// <param name="start">The starting vakue of the size</param> /// <param name="end">The ending value of the size</param> /// <param name="length">The time, in milliseconds, for the animation to last</param> void SetupSizeAnimation(Size start, Size end, int length) { //checks to see if the window isn't being animated if (!animating) { //inverts the debug bool debugOpen = !debugOpen; //lets the program know that the animation is running animating = true; timeLeft = length; //figures out how many time steps there will be int timeSteps = timeLeft / SizeAnimationTimer.Interval; Point sizeAnimationDifference = new Point(); //gets the size difference from the start size to the end size sizeAnimationDifference.X = end.Width - start.Width; sizeAnimationDifference.Y = end.Height - start.Height; sizeAnimationStep = new Point(); //figures out how much to increase the size each tick sizeAnimationStep.X = sizeAnimationDifference.X / timeSteps; sizeAnimationStep.Y = sizeAnimationDifference.Y / timeSteps; SizeAnimationTimer.Start(); } }
/// <summary> /// Animates the resize of the window /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void AnimateResize(object sender, EventArgs e) { //makes sure that the timer is ticking for the right amount of time if (timeLeft > 0) { //Console.WriteLine(timeLeft); Size newSize = new Size(Size.Width + sizeAnimationStep.X, Size.Height + sizeAnimationStep.Y); Size = newSize; } else { //stops the timer is too long has passed SizeAnimationTimer.Stop(); animating = false; } //keeps track of how much time has passed timeLeft -= (int)SizeAnimationTimer.Interval; }