private void MovePageTo(PageSliderPage page, PageSlider slider, int newIndex)
        {
            IDesignerHost dh = this.GetService(typeof(IDesignerHost)) as IDesignerHost;
            IComponentChangeService cc = this.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
            ISelectionService ss = this.GetService(typeof(ISelectionService)) as ISelectionService;

            DesignerTransaction dt = dh.CreateTransaction("Moving page");
            if (cc != null)
                cc.OnComponentChanging(slider, TypeDescriptor.GetProperties(slider)["Controls"]);
            slider.Controls.SetChildIndex(page, newIndex);
            if (cc != null)
                cc.OnComponentChanged(slider, TypeDescriptor.GetProperties(slider)["Controls"], null, null);
            dt.Commit();
        }
Esempio n. 2
0
        private void AnimatePageTransition(PageSliderPage oldValue, PageSliderPage newValue)
        {
            int oldIndex = -1;
            if (oldValue != null)
                oldIndex = _PageTable.IndexOf(oldValue);
            int newIndex = -1;
            if (newValue != null)
                newIndex = _PageTable.IndexOf(newValue);
            if (oldIndex == newIndex)
            {
                UpdateBoundsForAllPages(false);
                _PageBoundsOffset = Point.Empty;
                return;
            }
            int totalOffset = 0;

            Rectangle selectedPageBounds = GetSelectedPageBounds();

            if (_Orientation == eOrientation.Horizontal)
            {
                totalOffset = ((oldIndex - newIndex) * (selectedPageBounds.Width + _PageSpacing)) - _PageBoundsOffset.X;
            }
            else
            {
                totalOffset = ((oldIndex - newIndex) * (selectedPageBounds.Height + _PageSpacing)) - _PageBoundsOffset.Y;
            }

            _PageBoundsOffset = Point.Empty;

            DateTime startingTime = DateTime.Now;
            int speedFactor = 1;
            int remainOffset = Math.Abs(totalOffset);
            int offsetSign = Math.Sign(totalOffset);
            int animationTimeDuration = _AnimationTime;

            if (_Orientation == eOrientation.Horizontal && remainOffset < selectedPageBounds.Width * .8 ||
                _Orientation == eOrientation.Vertical && remainOffset < selectedPageBounds.Height * .8)
            {
                if (_Orientation == eOrientation.Horizontal)
                    animationTimeDuration *= (remainOffset / selectedPageBounds.Width);
                else
                    animationTimeDuration *= (remainOffset / selectedPageBounds.Height);
                animationTimeDuration = Math.Max(animationTimeDuration, 50);
            }

            TimeSpan animationTime = new TimeSpan(0, 0, 0, 0, animationTimeDuration);
            while (remainOffset > 0)
            {
                DateTime startPerMove = DateTime.Now;

                foreach (PageSliderPage page in _PageTable)
                {
                    Rectangle bounds = page.Bounds;
                    if (_Orientation == eOrientation.Horizontal)
                        bounds.Offset(speedFactor * offsetSign, 0);
                    else
                        bounds.Offset(0, speedFactor * offsetSign);
                    page.Bounds = bounds;
                    if (bounds.IntersectsWith(this.ClientRectangle))
                        this.Update();
                }
                remainOffset -= speedFactor;
                TimeSpan elapsedPerMove = DateTime.Now - startPerMove;
                TimeSpan elapsedTime = DateTime.Now - startingTime;
                if ((animationTime - elapsedTime).TotalMilliseconds <= 0)
                    speedFactor = remainOffset;
                else
                {
                    if ((int)(animationTime - elapsedTime).TotalMilliseconds == 0)
                        speedFactor = 1;
                    else
                        speedFactor = remainOffset * (int)elapsedPerMove.TotalMilliseconds / Math.Max(1, (int)((animationTime - elapsedTime).TotalMilliseconds));
                }
                if (speedFactor > remainOffset) speedFactor = remainOffset;
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Called when SelectedPage property has changed.
 /// </summary>
 /// <param name="oldValue">Old property value</param>
 /// <param name="newValue">New property value</param>
 protected virtual void OnSelectedPageChanged(PageSliderPage oldValue, PageSliderPage newValue)
 {
     //OnPropertyChanged(new PropertyChangedEventArgs("SelectedPage"));
     if (_AnimationTime > 0)
         AnimatePageTransition(oldValue, newValue);
     else
         UpdateBoundsForAllPages(false);
     //if (newValue != null)
     //{
     //    newValue.Bounds = GetPageBounds(newValue);
     //    newValue.BringToFront();
     //}
     UpdateScrollBar();
     _StepIndicator.CurrentStep = this.SelectedPageIndex + 1;
     OnSelectedPageChanged(EventArgs.Empty);
 }
Esempio n. 4
0
        private System.Drawing.Rectangle GetPageBounds(PageSliderPage page)
        {
            int pageIndex = _PageTable.IndexOf(page);
            int selectedPageIndex = this.SelectedPageIndex;
            Rectangle bounds = Rectangle.Empty;

            Rectangle selectedPageBounds = GetSelectedPageBounds();

            if (pageIndex == selectedPageIndex)
            {
                bounds = selectedPageBounds;
            }
            else if (pageIndex > selectedPageIndex)
            {
                bounds = selectedPageBounds;
                if (_Orientation == eOrientation.Horizontal)
                    bounds.X += (_PageSpacing + bounds.Width) * (pageIndex - selectedPageIndex);
                else
                    bounds.Y += (_PageSpacing + bounds.Height) * (pageIndex - selectedPageIndex);
            }
            else
            {
                bounds = selectedPageBounds;
                if (_Orientation == eOrientation.Horizontal)
                    bounds.X -= (_PageSpacing + bounds.Width) * (selectedPageIndex - pageIndex);
                else
                    bounds.Y -= (_PageSpacing + bounds.Height) * (selectedPageIndex - pageIndex);
            }

            bounds.Offset(_PageBoundsOffset);

            return bounds;
        }