示例#1
0
        private void MoveTimer_Elapsed()
        {
            int desktopX = this.DesktopLocation.X;
            int desktopY = this.DesktopLocation.Y;

            if (this.Visible && (desktopX != targetPositionX || desktopY != targetPositionY || targetOpacity != Opacity))
            {
                int    updatedX, updatedY;
                double updatedOpacity;
                if (animations)
                {
                    updatedX       = Math.Abs(desktopX - targetPositionX) < 3 ? targetPositionX : (int)(desktopX + (targetPositionX - desktopX) / 5.0);
                    updatedY       = Math.Abs(desktopY - targetPositionY) < 3 ? targetPositionY : (int)(desktopY + (targetPositionY - desktopY) / 5.0);
                    updatedOpacity = Math.Abs(targetOpacity - Opacity) < 0.1 ? targetOpacity : Opacity + (targetOpacity - Opacity) / 10.0;
                }
                else
                {
                    updatedX       = targetPositionX;
                    updatedY       = targetPositionY;
                    updatedOpacity = targetOpacity;
                }
                try {
                    this.Invoke((MethodInvoker) delegate {
                        if (!this.IsDisposed)
                        {
                            this.SetDesktopLocation(updatedX, updatedY);
                            this.Opacity = updatedOpacity;
                            if (updatedOpacity <= 0 || (targetOpacity == 0 && !animations))
                            {
                                moveTimer.Dispose();
                                close();
                            }
                        }
                    });
                } catch {
                }
                moveTimer.Interval = 1;
            }
            else
            {
                moveTimer.Interval = 100;
            }
        }