/// <summary> /// Set the state for this panel /// </summary> private void SetState() { if (captionCtrl.Width >= captionCtrl.Height) { if (captionCtrl.Height == Height) { state = ExtendedPanelState.Collapsed; } else { state = ExtendedPanelState.Expanded; } } else { if (captionCtrl.Width == Width) { state = ExtendedPanelState.Collapsed; } else { state = ExtendedPanelState.Expanded; } } }
/// <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(); }