Exemplo n.º 1
0
        /// <summary>
        /// Event raised for exapanding/collapsing the control
        /// </summary>
        /// <param name="sender">instance of the object raising the event</param>
        /// <param name="e">instance of an object containing the event data</param>
        private void CollapsingHandler(object sender, ChangeStyleEventArgs e)
        {
            //check to see  if Anchoring needs special treatment
            if (this.captionAlign == DirectionStyle.Right || this.captionAlign == DirectionStyle.Down)
            {
                backupAnchor = this.Anchor;
                this.Anchor |= AnchorStyles.Left;
                this.Anchor |= AnchorStyles.Top;
                this.Anchor &= ~AnchorStyles.Right;
                this.Anchor &= ~AnchorStyles.Bottom;
            }
            //create the thread for collasping/expanding the control
            if (null == collapseAnimation)
            {
                collapseAnimation = new CollapseAnimation();
                //set the events to be raised by the animation worker thread
                collapseAnimation.NotifyAnimation         += new NotifyAnimationEvent(OnNotifyAnimationEvent);
                collapseAnimation.NotifyAnimationFinished += new NotifyAnimationFinishedEvent(OnNotifyAnimationFinished);
                if (backupHeight == 0)
                {
                    backupHeight = this.Height;
                }
                if (backupWidth == 0)
                {
                    backupWidth = this.Width;
                }
            }

            switch (this.captionAlign)
            {
            case DirectionStyle.Up:
                if (e.Old == DirectionStyle.Up)
                {
                    backupHeight = this.Height;
                    backupWidth  = this.Width;

                    collapseAnimation.Maximum = this.Height;
                    collapseAnimation.Minimum = captionCtrl.Height;
                    if (animation == Animation.Yes)
                    {
                        collapseAnimation.Step = step;
                    }
                    else
                    {
                        collapseAnimation.Step = this.Height - captionCtrl.Height;
                    }
                }
                else
                {
                    collapseAnimation.Maximum = backupHeight;
                    collapseAnimation.Minimum = captionCtrl.Height;
                    if (animation == Animation.Yes)
                    {
                        collapseAnimation.Step = -step;
                    }
                    else
                    {
                        collapseAnimation.Step = -(backupHeight - captionCtrl.Height);
                    }
                }
                break;

            case DirectionStyle.Down:
                if (e.Old == DirectionStyle.Down)
                {
                    //have to extract caption ctrl because of the flickering involved
                    ChangeCaptionParent();

                    //save the size as will need them for expanding the control back
                    backupHeight = this.Height;
                    backupWidth  = this.Width;

                    collapseAnimation.Maximum = this.Height;
                    collapseAnimation.Minimum = captionCtrl.Height;
                    if (animation == Animation.Yes)
                    {
                        collapseAnimation.Step = step;
                    }
                    else
                    {
                        collapseAnimation.Step = this.Height - captionCtrl.Height;
                    }
                }
                else
                {
                    //have to extract caption ctrl because of the flickering involved
                    ChangeCaptionParent();

                    collapseAnimation.Maximum = backupHeight;
                    collapseAnimation.Minimum = captionCtrl.Height;
                    if (animation == Animation.Yes)
                    {
                        collapseAnimation.Step = -step;
                    }
                    else
                    {
                        collapseAnimation.Step = -(backupHeight - captionCtrl.Height);
                    }
                }
                break;


            case DirectionStyle.Left:
                if (e.Old == DirectionStyle.Left)
                {
                    //save the size as will need them for expanding the control back
                    backupHeight = this.Height;
                    backupWidth  = this.Width;

                    collapseAnimation.Maximum = this.Width;
                    collapseAnimation.Minimum = captionCtrl.Width;
                    if (animation == Animation.Yes)
                    {
                        collapseAnimation.Step = step;
                    }
                    else
                    {
                        collapseAnimation.Step = this.Width - captionCtrl.Width;
                    }
                }
                else
                {
                    collapseAnimation.Maximum = backupWidth;
                    collapseAnimation.Minimum = captionCtrl.Width;
                    if (animation == Animation.Yes)
                    {
                        collapseAnimation.Step = -step;
                    }
                    else
                    {
                        collapseAnimation.Step = -(backupWidth - captionCtrl.Width);
                    }
                }
                break;

            case DirectionStyle.Right:
                if (e.Old == DirectionStyle.Right)
                {
                    //have to extract caption ctrl because of the flickering involved
                    ChangeCaptionParent();

                    backupHeight = this.Height;
                    backupWidth  = this.Width;

                    collapseAnimation.Maximum = this.Width;
                    collapseAnimation.Minimum = captionCtrl.Width;
                    if (animation == Animation.Yes)
                    {
                        collapseAnimation.Step = step;
                    }
                    else
                    {
                        collapseAnimation.Step = this.Width - captionCtrl.Width;
                    }
                }
                else
                {
                    //have to extract caption ctrl because of the flickering involved
                    ChangeCaptionParent();

                    collapseAnimation.Maximum = backupWidth;
                    collapseAnimation.Minimum = captionCtrl.Width;
                    if (animation == Animation.Yes)
                    {
                        collapseAnimation.Step = -step;
                    }
                    else
                    {
                        collapseAnimation.Step = -(backupWidth - captionCtrl.Width);
                    }
                }
                break;
            }

            SetState();
            ShowControls();
            //start collapsing/expanding and set the new state
            if (state == ExtendedPanelState.Collapsed)
            {
                state = ExtendedPanelState.Expanding;
            }
            else
            {
                if (state == ExtendedPanelState.Expanded)
                {
                    state = ExtendedPanelState.Collapsing;
                }
            }
            collapseAnimation.Start();
        }
        /// <summary>
        ///   Event raised for exapanding/collapsing the control
        /// </summary>
        /// <param name = "sender">instance of the object raising the event</param>
        /// <param name = "e">instance of an object containing the event data</param>
        private void CollapsingHandler(object sender, ChangeStyleEventArgs e)
        {
            //check to see  if Anchoring needs special treatment
              if (captionAlign == DirectionStyle.Right || captionAlign == DirectionStyle.Down)
              {
            backupAnchor = Anchor;
            Anchor |= AnchorStyles.Left;
            Anchor |= AnchorStyles.Top;
            Anchor &= ~AnchorStyles.Right;
            Anchor &= ~AnchorStyles.Bottom;
              }
              //create the thread for collasping/expanding the control
              if (null == collapseAnimation)
              {
            collapseAnimation = new CollapseAnimation();
            //set the events to be raised by the animation worker thread
            collapseAnimation.NotifyAnimation += OnNotifyAnimationEvent;
            collapseAnimation.NotifyAnimationFinished += OnNotifyAnimationFinished;
            if (backupHeight == 0)
            {
              backupHeight = Height;
            }
            if (backupWidth == 0)
            {
              backupWidth = Width;
            }
              }

              switch (captionAlign)
              {
            case DirectionStyle.Up:
              if (e.Old == DirectionStyle.Up)
              {
            backupHeight = Height;
            backupWidth = Width;

            collapseAnimation.Maximum = Height;
            collapseAnimation.Minimum = captionCtrl.Height;
            if (animation == Animation.Yes)
            {
              collapseAnimation.Step = step;
            }
            else
            {
              collapseAnimation.Step = Height - captionCtrl.Height;
            }
              }
              else
              {
            collapseAnimation.Maximum = backupHeight;
            collapseAnimation.Minimum = captionCtrl.Height;
            if (animation == Animation.Yes)
            {
              collapseAnimation.Step = -step;
            }
            else
            {
              collapseAnimation.Step = -(backupHeight - captionCtrl.Height);
            }
              }
              break;

            case DirectionStyle.Down:
              if (e.Old == DirectionStyle.Down)
              {
            //have to extract caption ctrl because of the flickering involved
            ChangeCaptionParent();

            //save the size as will need them for expanding the control back
            backupHeight = Height;
            backupWidth = Width;

            collapseAnimation.Maximum = Height;
            collapseAnimation.Minimum = captionCtrl.Height;
            if (animation == Animation.Yes)
            {
              collapseAnimation.Step = step;
            }
            else
            {
              collapseAnimation.Step = Height - captionCtrl.Height;
            }
              }
              else
              {
            //have to extract caption ctrl because of the flickering involved
            ChangeCaptionParent();

            collapseAnimation.Maximum = backupHeight;
            collapseAnimation.Minimum = captionCtrl.Height;
            if (animation == Animation.Yes)
            {
              collapseAnimation.Step = -step;
            }
            else
            {
              collapseAnimation.Step = -(backupHeight - captionCtrl.Height);
            }
              }
              break;

            case DirectionStyle.Left:
              if (e.Old == DirectionStyle.Left)
              {
            //save the size as will need them for expanding the control back
            backupHeight = Height;
            backupWidth = Width;

            collapseAnimation.Maximum = Width;
            collapseAnimation.Minimum = captionCtrl.Width;
            if (animation == Animation.Yes)
            {
              collapseAnimation.Step = step;
            }
            else
            {
              collapseAnimation.Step = Width - captionCtrl.Width;
            }
              }
              else
              {
            collapseAnimation.Maximum = backupWidth;
            collapseAnimation.Minimum = captionCtrl.Width;
            if (animation == Animation.Yes)
            {
              collapseAnimation.Step = -step;
            }
            else
            {
              collapseAnimation.Step = -(backupWidth - captionCtrl.Width);
            }
              }
              break;

            case DirectionStyle.Right:
              if (e.Old == DirectionStyle.Right)
              {
            //have to extract caption ctrl because of the flickering involved
            ChangeCaptionParent();

            backupHeight = Height;
            backupWidth = Width;

            collapseAnimation.Maximum = Width;
            collapseAnimation.Minimum = captionCtrl.Width;
            if (animation == Animation.Yes)
            {
              collapseAnimation.Step = step;
            }
            else
            {
              collapseAnimation.Step = Width - captionCtrl.Width;
            }
              }
              else
              {
            //have to extract caption ctrl because of the flickering involved
            ChangeCaptionParent();

            collapseAnimation.Maximum = backupWidth;
            collapseAnimation.Minimum = captionCtrl.Width;
            if (animation == Animation.Yes)
            {
              collapseAnimation.Step = -step;
            }
            else
            {
              collapseAnimation.Step = -(backupWidth - captionCtrl.Width);
            }
              }
              break;
              }

              SetState();
              ShowControls();
              //start collapsing/expanding and set the new state
              if (state == ExtendedPanelState.Collapsed)
              {
            state = ExtendedPanelState.Expanding;
              }
              else
              {
            if (state == ExtendedPanelState.Expanded)
            {
              state = ExtendedPanelState.Collapsing;
            }
              }
              collapseAnimation.Start();
        }