/// <summary> /// Creates and starts a new asynchronous <see cref="DelayedCall" /> instance. The callback /// function will be invoked on a ThreadPool thread. /// </summary> /// <param name="cb">The callback function.</param> /// <param name="milliseconds">Time to callback invocation in milliseconds.</param> /// <returns>The created <see cref="DelayedCall" /> instance that can be used for later controlling of the invocation process.</returns> public static DelayedCall StartAsync(Callback cb, int milliseconds) { DelayedCall dc = CreateAsync(cb, milliseconds); if (milliseconds > 0) { dc.Start(); } else if (milliseconds == 0) { dc.FireNow(); } return(dc); }
/// <summary> /// Reverseds this instance. /// </summary> public void Reversed() { timePassed += interval - interval + 2; try { Control c; System.Windows.Forms.Form f; Rectangle wa; switch (type) { case AnimationTypes.MoveUp: c = target as Control; c.Location = new Point(c.Location.X, (int)start + (int)(((end / offset) - (start / offset) + offset / mover) * MakeCurve())); //----------Wider----------// //c.Location = new Point(c.Location.X, (int)start + (int)((end - start) * MakeCurve())); wa = Screen.FromControl(c).WorkingArea; if (c is System.Windows.Forms.Form && c.Bottom < wa.Bottom) { //int Y = c.Location.Y; int Y = (int)start + (int)((end - start) * MakeCurve()); Y += c.Location.Y + wa.Y; //c.Location = new Point(c.Location.X, Y); //if (c.Top > wa.Top) //{ // c.Top = wa.Top; //} } break; case AnimationTypes.MoveLeft: c = target as Control; c.Location = new Point((int)start + (int)(((end / offset) - (start / offset) + offset / mover) * MakeCurve()), c.Location.Y); //---------------Wider-------------// //c.Location = new Point((int)start + (int)((end - start) * MakeCurve()), c.Location.Y); wa = Screen.FromControl(c).WorkingArea; if (c is System.Windows.Forms.Form && c.Right < wa.Right) { //int X = c.Location.X; int X = (int)start + (int)((end - start) * MakeCurve()); X += c.Location.X + wa.X; //c.Location = new Point(X, c.Location.Y); //if (c.Left > wa.Left) //{ // c.Left = wa.Left; //} } break; #region Right and Down case AnimationTypes.MoveDown: c = target as Control; #region Move Up Works c.Location = new Point(c.Location.X, (int)start - (int)(((end / offset) - (start / offset) + offset / mover) * MakeCurve())); //------------Wider-------------// //c.Location = new Point(c.Location.X, (int)start - (int)(((end) - (start) + offset / mover) * MakeCurve())); wa = Screen.FromControl(c).WorkingArea; #region Bounds Imposition //if (c is System.Windows.Forms.Form && c.Bottom < wa.Bottom) //{ // c.Top += c.Bottom + wa.Bottom; // if (c.Top > wa.Top) // { // c.Top = wa.Top; // } //} #endregion #endregion break; case AnimationTypes.MoveRight: c = target as Control; c.Location = new Point((int)start - (int)(((end / offset) - (start / offset) + offset / mover) * MakeCurve()), c.Location.Y); //------------Wider-------------// //c.Location = new Point((int)start - (int)(((end) - (start) + offset / mover) * MakeCurve()), c.Location.Y); break; #endregion case AnimationTypes.FadeIn: f = target as System.Windows.Forms.Form; f.Opacity = (float)(end + ((start - end) * MakeCurve())) / 100; break; case AnimationTypes.FadeOut: f = target as System.Windows.Forms.Form; f.Opacity = (float)(end + ((start - end) * MakeCurve())) / 100; break; case AnimationTypes.Callback: callback(target, (int)end + (int)((start - end) * MakeCurve())); break; } DelayedCall.Start(Reversed, interval); } catch (ObjectDisposedException e) { MessageBox.Show(e.Message); } }
/// <summary> /// Nexts this instance. /// </summary> public void Next() { if (cancellationPending) { return; // and don't come back } timePassed += interval + interval; if (timePassed > duration) { if (handler != null) { handler(target); } return; } try { Control c; System.Windows.Forms.Form f; Rectangle wa; switch (type) { case AnimationTypes.MoveUp: c = target as Control; c.Location = new Point(c.Location.X, (int)start + (int)(((end / offset) - (start / offset) + offset / mover) * MakeCurve())); //----------Wider----------// //c.Location = new Point(c.Location.X,(int)start + (int)((end - start) * MakeCurve())); wa = Screen.FromControl(c).WorkingArea; if (c is System.Windows.Forms.Form && c.Top < wa.Top) { c.Top = wa.Top; } break; case AnimationTypes.MoveLeft: c = target as Control; c.Location = new Point((int)start + (int)(((end / offset) - (start / offset) + offset / mover) * MakeCurve()), c.Location.Y); //----------Wider----------// //c.Location = new Point((int)start + (int)((end - start) * MakeCurve()),c.Location.Y); wa = Screen.FromControl(c).WorkingArea; if (c is System.Windows.Forms.Form && c.Location.X > wa.X) { //int X = c.Location.X; int X = (int)start + (int)((end - start) * MakeCurve()); X -= c.Location.X - wa.X; //c.Location = new Point(X, c.Location.Y); //if (c.Left < wa.Left) //{ // c.Left = wa.Left ; //} } break; #region Right and Down case AnimationTypes.MoveDown: c = target as Control; #region Move Down Works c.Location = new Point(c.Location.X, (int)start + (int)(((end / offset) - (start / offset) + offset / mover) * MakeCurve())); //------------Wider-------------// //c.Location = new Point(c.Location.X, (int)start + (int)(((end) - (start) + offset / mover) * MakeCurve())); #endregion #region Move Up Works //c.Location = new Point(c.Location.X, (int)start - (int)(((end / offset) - (start / offset) + offset / mover) * MakeCurve())); #endregion wa = Screen.FromControl(c).WorkingArea; //if (c is System.Windows.Forms.Form && c.Bottom < wa.Bottom) //{ // //int Y = c.Location.Y; // int Y = (int)start + (int)((end - start) * MakeCurve()); // Y += c.Location.Y + wa.Y; // //c.Location = new Point(c.Location.X, Y); // //if (c.Top > wa.Top) // //{ // // c.Top = wa.Top; // //} //} #region Bounds Imposition //if (c is System.Windows.Forms.Form && c.Bottom > wa.Bottom) //{ // c.Top -= c.Bottom - wa.Bottom; // if (c.Top < wa.Top) // { // c.Top = wa.Top; // } //} #endregion break; case AnimationTypes.MoveRight: c = target as Control; c.Location = new Point((int)start + (int)(((end / offset) - (start / offset) + offset / mover) * MakeCurve()), c.Location.Y); //------------Wider-------------// //c.Location = new Point((int)start + (int)(((end) - (start) + offset / mover) * MakeCurve()), c.Location.Y); wa = Screen.FromControl(c).WorkingArea; #region Bounds Imposition //if (c is System.Windows.Forms.Form && c.Right > wa.Right) //{ // c.Left -= c.Right - wa.Right; // if (c.Left < wa.Left) // { // c.Left = wa.Left; // } //} #endregion break; #endregion case AnimationTypes.FadeIn: f = target as System.Windows.Forms.Form; f.Opacity = (float)(start * MakeCurve()) / 100; break; case AnimationTypes.FadeOut: f = target as System.Windows.Forms.Form; f.Opacity = (float)(start + ((end - start) * MakeCurve())) / 100; break; case AnimationTypes.Callback: callback(target, (int)start + (int)((end - start) * MakeCurve())); break; } DelayedCall.Start(Next, interval); } catch (Exception e) { // Control is gone, stop here } }
/// <summary> /// Reverseds this instance. /// </summary> public void Reversed() { timePassed += interval - interval + 2; try { Control c; System.Windows.Forms.Form f; Rectangle wa; switch (type) { case AnimationTypes.ResizeVert: c = target as Control; c.Height = (int)end + (int)((start - end) * MakeCurve()); wa = Screen.FromControl(c).WorkingArea; if (c is System.Windows.Forms.Form && c.Bottom < wa.Bottom) { c.Top += c.Bottom + wa.Bottom; if (c.Top > wa.Top) { c.Top = wa.Top; } } break; case AnimationTypes.ResizeHoriz: c = target as Control; c.Width = (int)end + (int)((start - end) * MakeCurve()); wa = Screen.FromControl(c).WorkingArea; if (c is System.Windows.Forms.Form && c.Right < wa.Right) { c.Left += c.Right + wa.Right; if (c.Left > wa.Left) { c.Left = wa.Left; } } break; case AnimationTypes.FadeIn: f = target as System.Windows.Forms.Form; f.Opacity = (float)(end + ((start - end) * MakeCurve())) / 100; break; case AnimationTypes.FadeOut: f = target as System.Windows.Forms.Form; f.Opacity = (float)(end + ((start - end) * MakeCurve())) / 100; break; case AnimationTypes.Callback: callback(target, (int)end + (int)((start - end) * MakeCurve())); break; } DelayedCall.Start(Reversed, interval); } catch (ObjectDisposedException e) { MessageBox.Show(e.Message); } }
/// <summary> /// Nexts this instance. /// </summary> public void Next() { if (cancellationPending) { return; // and don't come back } timePassed += interval + interval; if (timePassed > duration) { if (handler != null) { handler(target); } return; } try { Control c; System.Windows.Forms.Form f; Rectangle wa; switch (type) { case AnimationTypes.ResizeVert: c = target as Control; c.Height = (int)start + (int)((end - start) * MakeCurve()); wa = Screen.FromControl(c).WorkingArea; if (c is System.Windows.Forms.Form && c.Bottom > wa.Bottom) { c.Top -= c.Bottom - wa.Bottom; if (c.Top < wa.Top) { c.Top = wa.Top; } } break; case AnimationTypes.ResizeHoriz: c = target as Control; c.Width = (int)start + (int)((end - start) * MakeCurve()); wa = Screen.FromControl(c).WorkingArea; if (c is System.Windows.Forms.Form && c.Right > wa.Right) { c.Left -= c.Right - wa.Right; if (c.Left < wa.Left) { c.Left = wa.Left; } } break; case AnimationTypes.FadeIn: f = target as System.Windows.Forms.Form; f.Opacity = (float)(start * MakeCurve()) / 100; break; case AnimationTypes.FadeOut: f = target as System.Windows.Forms.Form; f.Opacity = (float)(start + ((end - start) * MakeCurve())) / 100; break; case AnimationTypes.Callback: callback(target, (int)start + (int)((end - start) * MakeCurve())); break; } DelayedCall.Start(Next, interval); } catch (Exception e) { // Control is gone, stop here } }