Example #1
0
		public ScrollEventArgs (ScrollEventType type, int oldValue, int newValue, ScrollOrientation scroll)
		{
			this.new_value = newValue;
			this.old_value = oldValue;
			this.scroll_orientation = scroll;
			this.type = type;
		}
        private void OnScroll(ScrollEventType type, int oldValue, int newValue, ScrollOrientation orientation)
        {
            if (Scroll == null) return;

            if (orientation == ScrollOrientation.HorizontalScroll)
            {
                if (type != ScrollEventType.EndScroll && isFirstScrollEventHorizontal)
                {
                    type = ScrollEventType.First;
                }
                else if (!isFirstScrollEventHorizontal && type == ScrollEventType.EndScroll)
                {
                    isFirstScrollEventHorizontal = true;
                }
            }
            else
            {
                if (type != ScrollEventType.EndScroll && isFirstScrollEventVertical)
                {
                    type = ScrollEventType.First;
                }
                else if (!isFirstScrollEventHorizontal && type == ScrollEventType.EndScroll)
                {
                    isFirstScrollEventVertical = true;
                }
            }

            Scroll(this, new ScrollEventArgs(type, oldValue, newValue, orientation));
        }
Example #3
0
        /// <summary>
        ///   Construct a new scrollbar
        /// </summary>
        protected AbstractScrollbar( ScrollOrientation orientation )
        {
            Orientation = orientation;

              InitializeComponent();
              InitializePixelMap();
        }
 public ScrollEventArgs(ScrollEventType type, int oldValue, int newValue, ScrollOrientation scroll)
 {
     _scrollType = type;
     _oldValue = oldValue;
     NewValue = newValue;
     _scrollOrientation = scroll;
 }
		public void GetsCorrectSizeRequestWithWrappingContent (ScrollOrientation orientation)
		{
			var scrollView = new ScrollView {
				IsPlatformEnabled = true,
				Orientation = orientation,
				Platform = new UnitPlatform (null, true)
			};

			var hLayout = new StackLayout {
				IsPlatformEnabled = true,
				Orientation = StackOrientation.Horizontal,
				Children = {
					new Label {Text = "THIS IS A REALLY LONG STRING", IsPlatformEnabled = true},
					new Label {Text = "THIS IS A REALLY LONG STRING", IsPlatformEnabled = true},
					new Label {Text = "THIS IS A REALLY LONG STRING", IsPlatformEnabled = true},
					new Label {Text = "THIS IS A REALLY LONG STRING", IsPlatformEnabled = true},
					new Label {Text = "THIS IS A REALLY LONG STRING", IsPlatformEnabled = true},
				}
			};

			scrollView.Content = hLayout;

			var r = scrollView.GetSizeRequest (100, 100);

			Assert.AreEqual (10, r.Request.Height);
		}
		public EmbeddedScrollBar(ScrollableView host, ScrollOrientation type)
		{
			this.host = host;
			this.type = type;

			info.size = Marshal.SizeOf(typeof(ScrollInfo));
			info.min = 0;
			info.max = 100;
			info.position = 0;
			info.trackPosition = 0;
			info.page = 10;
			info.flags = ScrollBarFlags.All;
		}
Example #7
0
        /// <include file='doc\ScrollBar.uex' path='docs/doc[@for="ScrollBar.ScrollBar"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Initializes a new instance of the <see cref='System.Windows.Forms.ScrollBar'/>
        ///       class.
        ///       
        ///    </para>
        /// </devdoc>
        public ScrollBar()
        : base() {
            SetStyle(ControlStyles.UserPaint, false);
            SetStyle(ControlStyles.StandardClick, false);
            SetStyle(ControlStyles.UseTextForAccessibility, false);

            TabStop = false;

            if ((this.CreateParams.Style & NativeMethods.SBS_VERT) != 0)
            {
                scrollOrientation = ScrollOrientation.VerticalScroll;
            }
            else
            {
                scrollOrientation = ScrollOrientation.HorizontalScroll;
            }
        }
Example #8
0
        private void WmOnScroll(ref System.Windows.Forms.Message m, int oldValue, int value, ScrollOrientation scrollOrientation)
        {
            var type = (ScrollEventType)NativeMethods.Util.LOWORD(m.WParam);

            if (type != ScrollEventType.EndScroll)
            {
                OnScroll(new ScrollEventArgs(type, oldValue, value, scrollOrientation));
            }
        }
        public void Ctor_ScrollEventType_Int_Int_ScrollOrientation(ScrollEventType type, int oldValue, int newValue, ScrollOrientation scroll)
        {
            var e = new ScrollEventArgs(type, oldValue, newValue, scroll);

            Assert.Equal(type, e.Type);
            Assert.Equal(oldValue, e.OldValue);
            Assert.Equal(newValue, e.NewValue);
            Assert.Equal(scroll, e.ScrollOrientation);
        }
Example #10
0
        /// <summary>
        /// Creation of an expression to manage modulo (positive and negative value)
        /// </summary>
        /// <param name="scrollViewer">The ScrollViewer to synchronized. A null value is valid</param>
        /// <param name="imageWidth">Width of the image</param>
        /// <param name="imageHeight">Height of the image</param>
        /// <param name="scrollOrientation">The ScrollOrientation</param>
        private void CreateModuloExpression(ScrollViewer scrollViewer, double imageWidth, double imageHeight, ScrollOrientation scrollOrientation)
        {
            const string propSetParam              = "p";
            const string offsetXParam              = nameof(OffsetX);
            const string qualifiedOffsetXParam     = propSetParam + "." + offsetXParam;
            const string offsetYParam              = nameof(OffsetY);
            const string qualifiedOffsetYParam     = propSetParam + "." + offsetYParam;
            const string imageWidthParam           = nameof(imageWidth);
            const string qualifiedImageWidthParam  = propSetParam + "." + imageWidthParam;
            const string imageHeightParam          = nameof(imageHeight);
            const string qualifiedImageHeightParam = propSetParam + "." + imageHeightParam;
            const string speedParam = nameof(ParallaxSpeedRatio);

            if (_containerVisual == null)
            {
                return;
            }

            var compositor = _containerVisual.Compositor;

            // Setup the expression
            var expressionX = compositor.CreateExpressionAnimation();
            var expressionY = compositor.CreateExpressionAnimation();

            var propertySetModulo = compositor.CreatePropertySet();

            propertySetModulo.InsertScalar(imageWidthParam, (float)imageWidth);
            propertySetModulo.InsertScalar(offsetXParam, (float)OffsetX);
            propertySetModulo.InsertScalar(imageHeightParam, (float)imageHeight);
            propertySetModulo.InsertScalar(offsetYParam, (float)OffsetY);
            propertySetModulo.InsertScalar(speedParam, (float)ParallaxSpeedRatio);

            expressionX.SetReferenceParameter(propSetParam, propertySetModulo);
            expressionY.SetReferenceParameter(propSetParam, propertySetModulo);

            string GenerateFormula(string common, string dimension)
            => string.Format(
                "{0} == 0 " +
                "? 0 " +
                ": {0} < 0 " +
                "? -(Abs({0} - (Ceil({0} / {1}) * {1})) % {1}) " +
                ": -({1} - ({0} % {1}))",
                common,
                dimension);

            string expressionXVal;
            string expressionYVal;

            if (scrollViewer == null)
            {
                // expressions are created to simulate a positive and negative modulo with the size of the image and the offset
                expressionXVal = GenerateFormula("Ceil(" + qualifiedOffsetXParam + ")", qualifiedImageHeightParam);

                expressionYVal = GenerateFormula("Ceil(" + qualifiedOffsetYParam + ")", qualifiedImageWidthParam);
            }
            else
            {
                // expressions are created to simulate a positive and negative modulo with the size of the image and the offset and the ScrollViewer offset (Translation)
                var          scrollProperties    = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollViewer);
                const string scrollParam         = "s";
                const string translationParam    = scrollParam + "." + nameof(scrollViewer.Translation);
                const string qualifiedSpeedParam = propSetParam + "." + speedParam;

                expressionX.SetReferenceParameter(scrollParam, scrollProperties);
                expressionY.SetReferenceParameter(scrollParam, scrollProperties);

                string GenerateParallaxFormula(string scrollTranslation, string speed, string offset, string dimension)
                => GenerateFormula(string.Format("Ceil(({0} * {1}) + {2})", scrollTranslation, speed, offset), dimension);

                expressionXVal = GenerateParallaxFormula(translationParam + "." + nameof(scrollViewer.Translation.X), qualifiedSpeedParam, qualifiedOffsetXParam, qualifiedImageWidthParam);

                expressionYVal = GenerateParallaxFormula(translationParam + "." + nameof(scrollViewer.Translation.Y), qualifiedSpeedParam, qualifiedOffsetYParam, qualifiedImageHeightParam);
            }

            if (scrollOrientation == ScrollOrientation.Horizontal || scrollOrientation == ScrollOrientation.Both)
            {
                expressionX.Expression = expressionXVal;

                if (scrollOrientation == ScrollOrientation.Horizontal)
                {
                    // In horizontal mode we never move the offset y
                    expressionY.Expression  = "0";
                    _containerVisual.Offset = new Vector3((float)OffsetY, 0, 0);
                }
            }

            if (scrollOrientation == ScrollOrientation.Vertical || scrollOrientation == ScrollOrientation.Both)
            {
                expressionY.Expression = expressionYVal;

                if (scrollOrientation == ScrollOrientation.Vertical)
                {
                    // In vertical mode we never move the offset x
                    expressionX.Expression  = "0";
                    _containerVisual.Offset = new Vector3(0, (float)OffsetX, 0);
                }
            }

            _containerVisual.StopAnimation("Offset.X");
            _containerVisual.StopAnimation("Offset.Y");

            _containerVisual.StartAnimation("Offset.X", expressionX);
            _containerVisual.StartAnimation("Offset.Y", expressionY);

            _propertySetModulo = propertySetModulo;
        }
Example #11
0
 public OrientationBasedMeasures(ScrollOrientation o)
 {
     ScrollOrientation = o;
 }
        /// <summary>
        /// Creation of an expression to manage modulo (positive and negative value)
        /// </summary>
        /// <param name="scrollviewer">The ScrollViewer to synchonized. A null value is valid</param>
        /// <param name="imageWidth">Width of the image</param>
        /// <param name="imageHeight">Height of the image</param>
        /// <param name="scrollOrientation">The ScrollOrientation</param>
        private void CreateModuloExpression(ScrollViewer scrollviewer, double imageWidth, double imageHeight, ScrollOrientation scrollOrientation)
        {
            const string offsetXParam     = "offsetX";
            const string offsetYParam     = "offsetY";
            const string imageWidthParam  = "imageWidth";
            const string imageHeightParam = "imageHeight";
            const string speedParam       = "speed";

            if (Strategy == UIStrategy.PureXaml)
            {
                return;
            }

            if (_containerVisual == null)
            {
                return;
            }

            var compositor = _containerVisual.Compositor;

            // Setup the expression
            ExpressionNode expressionX    = null;
            ExpressionNode expressionY    = null;
            ExpressionNode expressionXVal = null;
            ExpressionNode expressionYVal = null;

            var propertySetModulo = compositor.CreatePropertySet();

            propertySetModulo.InsertScalar(imageWidthParam, (float)imageWidth);
            propertySetModulo.InsertScalar(offsetXParam, (float)OffsetX);
            propertySetModulo.InsertScalar(imageHeightParam, (float)imageHeight);
            propertySetModulo.InsertScalar(offsetYParam, (float)OffsetY);
            propertySetModulo.InsertScalar(speedParam, (float)ParallaxSpeedRatio);

            var propertySetNodeModulo = propertySetModulo.GetReference();

            var imageHeightNode = propertySetNodeModulo.GetScalarProperty(imageHeightParam);
            var imageWidthNode  = propertySetNodeModulo.GetScalarProperty(imageWidthParam);

            if (scrollviewer == null)
            {
                var offsetXNode = ExpressionFunctions.Ceil(propertySetNodeModulo.GetScalarProperty(offsetXParam));
                var offsetYNode = ExpressionFunctions.Ceil(propertySetNodeModulo.GetScalarProperty(offsetYParam));

                // expressions are created to simulate a positive and negative modulo with the size of the image and the offset
                expressionXVal = ExpressionFunctions.Conditional(
                    offsetXNode == 0,
                    0,
                    ExpressionFunctions.Conditional(
                        offsetXNode < 0,
                        -(ExpressionFunctions.Abs(offsetXNode - (ExpressionFunctions.Ceil(offsetXNode / imageWidthNode) * imageWidthNode)) % imageWidthNode),
                        -(imageWidthNode - (offsetXNode % imageWidthNode))));

                expressionYVal = ExpressionFunctions.Conditional(
                    offsetYNode == 0,
                    0,
                    ExpressionFunctions.Conditional(
                        offsetYNode < 0,
                        -(ExpressionFunctions.Abs(offsetYNode - (ExpressionFunctions.Ceil(offsetYNode / imageHeightNode) * imageHeightNode)) % imageHeightNode),
                        -(imageHeightNode - (offsetYNode % imageHeightNode))));
            }
            else
            {
                // expressions are created to simulate a positive and negative modulo with the size of the image and the offset and the ScrollViewer offset (Translation)
                var scrollProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollviewer);
                var scrollPropSet    = scrollProperties.GetSpecializedReference <ManipulationPropertySetReferenceNode>();

                var speed   = propertySetNodeModulo.GetScalarProperty(speedParam);
                var xCommon = ExpressionFunctions.Ceil((scrollPropSet.Translation.X * speed) + propertySetNodeModulo.GetScalarProperty(offsetXParam));
                expressionXVal = ExpressionFunctions.Conditional(
                    xCommon == 0,
                    0,
                    ExpressionFunctions.Conditional(
                        xCommon < 0,
                        -(ExpressionFunctions.Abs(xCommon - (ExpressionFunctions.Ceil(xCommon / imageWidthNode) * imageWidthNode)) % imageWidthNode),
                        -(imageWidthNode - (xCommon % imageWidthNode))));

                var yCommon = ExpressionFunctions.Ceil((scrollPropSet.Translation.Y * speed) + propertySetNodeModulo.GetScalarProperty(offsetYParam));
                expressionYVal = ExpressionFunctions.Conditional(
                    yCommon == 0,
                    0,
                    ExpressionFunctions.Conditional(
                        yCommon < 0,
                        -(ExpressionFunctions.Abs(yCommon - (ExpressionFunctions.Ceil(yCommon / imageHeightNode) * imageHeightNode)) % imageHeightNode),
                        -(imageHeightNode - (yCommon % imageHeightNode))));
            }

            if (scrollOrientation == ScrollOrientation.Horizontal || scrollOrientation == ScrollOrientation.Both)
            {
                expressionX = expressionXVal;

                if (scrollOrientation == ScrollOrientation.Horizontal)
                {
                    // In horizontal mode we never move the offset y
                    expressionY             = (ScalarNode)0.0f;
                    _containerVisual.Offset = new Vector3((float)OffsetY, 0, 0);
                }
            }

            if (scrollOrientation == ScrollOrientation.Vertical || scrollOrientation == ScrollOrientation.Both)
            {
                expressionY = expressionYVal;

                if (scrollOrientation == ScrollOrientation.Vertical)
                {
                    // In vertical mode we never move the offset x
                    expressionX             = (ScalarNode)0.0f;
                    _containerVisual.Offset = new Vector3(0, (float)OffsetX, 0);
                }
            }

            _containerVisual.StopAnimation("Offset.X");
            _containerVisual.StopAnimation("Offset.Y");

            _containerVisual.StartAnimation("Offset.X", expressionX);
            _containerVisual.StartAnimation("Offset.Y", expressionY);

            _propertySetModulo = propertySetModulo;
        }
Example #13
0
 public static Orientation ToOrthogonalLayoutOrientation(this ScrollOrientation scrollOrientation)
 {
     return(scrollOrientation == ScrollOrientation.Horizontal ? Orientation.Vertical : Orientation.Horizontal);
 }
Example #14
0
		public ScrollEventArgs (ScrollEventType type, int newValue, ScrollOrientation scroll) :
			this (type, -1, newValue, scroll)
		{
		}
 public ScrollEventArgs(ScrollEventType type, int oldValue, int newValue, ScrollOrientation scroll)
 {
 }
Example #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ScrollEventArgs"/> class using the given values for the <see cref="Type"/>, <see cref="OldValue"/>, <see cref="NewValue"/>, and <see cref="ScrollOrientation"/> properties.
 /// </summary>
 /// <param name="type">One of the <see cref="ScrollEventType"/> values.</param>
 /// <param name="oldValue">The old value for the scroll bar.</param>
 /// <param name="newValue">The new value for the scroll bar.</param>
 /// <param name="scroll">One of the <see cref="ScrollOrientation"/> values.</param>
 /// <remarks>
 /// http://msdn.microsoft.com/en-us/library/wy4h3cfs(v=vs.110).aspx
 /// </remarks>
 public ScrollEventArgs(ScrollEventType type, int oldValue, int newValue, ScrollOrientation scroll)
     : this(type, oldValue, newValue)
 {
     ScrollOrientation = scroll;
 }
 ScrollEventArgs(ScrollEventType type, int newValue, ScrollOrientation scroll) :
     this(type, -1, newValue, scroll)
 {
 }
        public void SetScrollValue(ScrollOrientation orientation, int value)
        {
            switch (orientation) {
                case ScrollOrientation.HorizontalScroll:
                    if (_scrollH != value) {
                        _scrollH = value;
                        CheckScrollValue();
                        OnScroll(new ScrollEventArgs(ScrollEventType.ThumbPosition, _scrollH, ScrollOrientation.HorizontalScroll));
                    }
                    break;
                case ScrollOrientation.VerticalScroll:
                    if (_scrollV != value) {
                        _scrollV = value;
                        CheckScrollValue();
                        OnScroll(new ScrollEventArgs(ScrollEventType.ThumbPosition, _scrollV, ScrollOrientation.VerticalScroll));
                    }
                    break;
            }

            Invalidate();
        }
Example #19
0
        private void ProcessWMScroll(int fnBar, int nScrollCode)
        {
            int large_change;
            int small_change;
            ScrollOrientation orientation = new ScrollOrientation();

            switch (fnBar)
            {
            case SB_VERT:
                large_change = VScrollLargeChange;
                small_change = VScrollSmallChange;
                orientation  = ScrollOrientation.VerticalScroll;
                break;

            case SB_HORZ:
                large_change = HScrollLargeChange;
                small_change = HScrollSmallChange;
                orientation  = ScrollOrientation.HorizontalScroll;
                break;

            default:
                throw new ArgumentOutOfRangeException("fnBar");
            }

            SCROLLINFO si = new SCROLLINFO();

            unsafe {
                si.cbSize = sizeof(SCROLLINFO);
                si.fMask  = SIF_ALL;
                GetScrollInfo(Handle, fnBar, new IntPtr(&si));
            }
            int oldValue = si.nPos;

            ScrollEventType type     = new ScrollEventType();
            int             newValue = si.nPos;

            switch (nScrollCode)
            {
            case SB_TOP:
                //case SB_LEFT:
                type     = ScrollEventType.First;
                newValue = si.nMin;
                break;

            case SB_BOTTOM:
                //case SB_RIGHT:
                type     = ScrollEventType.Last;
                newValue = si.nMax;
                break;

            case SB_LINEUP:
                //case SB_LINELEFT:
                type      = ScrollEventType.SmallDecrement;
                newValue -= small_change;
                break;

            case SB_LINEDOWN:
                //case SB_LINERIGHT:
                type      = ScrollEventType.SmallIncrement;
                newValue += small_change;
                break;

            case SB_PAGEUP:
                //case SB_PAGELEFT:
                type      = ScrollEventType.LargeDecrement;
                newValue -= large_change;
                break;

            case SB_PAGEDOWN:
                //case SB_PAGERIGHT:
                type      = ScrollEventType.LargeIncrement;
                newValue += large_change;
                break;

            case SB_THUMBPOSITION:
                type     = ScrollEventType.ThumbPosition;
                newValue = si.nTrackPos;
                break;

            case SB_THUMBTRACK:
                type     = ScrollEventType.ThumbTrack;
                newValue = si.nTrackPos;
                break;

            case SB_ENDSCROLL:
                type = ScrollEventType.EndScroll;
                break;

            default:
                throw new ArgumentOutOfRangeException("nScrollCode");
            }

            Point newPosition = scrollPosition;

            switch (orientation)
            {
            case ScrollOrientation.VerticalScroll:
                newPosition.Y = newValue;
                break;

            case ScrollOrientation.HorizontalScroll:
                newPosition.X = newValue;
                break;
            }
            ScrollWindowCore(newPosition);

            ScrollEventArgs se = new ScrollEventArgs(type, oldValue, newValue, orientation);

            OnScroll(se);
        }
 public ScrollEventArgs(ScrollEventType type, int newValue, ScrollOrientation scroll)
 {
 }
        /// <summary>
        ///   Gets scrollbar properties
        /// </summary>
        /// <param name="scrollbar">The bar.</param>
        /// <returns></returns>
        private NativeMethods.SCROLLINFO GetScrollInfo(ScrollOrientation scrollbar)
        {
            NativeMethods.SCROLLINFO info;

            info = new NativeMethods.SCROLLINFO();
            info.fMask = NativeMethods.SIF.SIF_ALL;

            NativeMethods.GetScrollInfo(this.Handle, (int)scrollbar, info);

            return info;
        }
Example #22
0
        protected override void OnScrollChanged(ScrollChangedEventArgs e)
        {
            //case 117456: Because the event is routed (bubble) we have to kill the event here so that other classes ( more particularly the
            // DataGridScrollViewer) does not get confused by the event.
            e.Handled = true;

            base.OnScrollChanged(e);

            // m_mainScrollViewer will remain null in design mode.
            // and if it's null, nothing to update
            if (m_mainScrollViewer == null)
            {
                return;
            }

            // Sometimes, a row in the SynchronizedScrollViewer will scroll by itself,
            // not triggered by the main ScrollViewer scrolling. In that case, we want
            // to update the main ScrollViewer. A typical example is when a Row's cell is
            // brought into view by, let's say, activating the cell editor.
            ScrollOrientation orientation = this.ScrollOrientation;

            bool invalidateMainScrollViewerMeasure = false;

            if ((orientation & ScrollOrientation.Horizontal) == ScrollOrientation.Horizontal)
            {
                invalidateMainScrollViewerMeasure = !DoubleUtil.AreClose(0, e.ExtentWidthChange);

                // If the Extent is 0, there is no reason to update
                // the main ScrollViewer offset since this means there
                // are no children
                if (this.ExtentWidth == 0)
                {
                    return;
                }

                double offset = (m_originalScrollChangedEventArgs != null)
          ? m_originalScrollChangedEventArgs.HorizontalOffset
          : e.HorizontalOffset;

                if (offset != m_mainScrollViewer.HorizontalOffset)
                {
                    m_mainScrollViewer.ScrollToHorizontalOffset(offset);
                }
            }

            if ((orientation & ScrollOrientation.Vertical) == ScrollOrientation.Vertical)
            {
                invalidateMainScrollViewerMeasure = !DoubleUtil.AreClose(0, e.ExtentHeightChange);

                // If the Extent is 0, there is no reason to update
                // the main ScrollViewer offset since this means there
                // are no children
                if (this.ExtentHeight == 0)
                {
                    return;
                }

                double offset = (m_originalScrollChangedEventArgs != null)
          ? m_originalScrollChangedEventArgs.VerticalOffset
          : e.VerticalOffset;

                if ((offset != m_mainScrollViewer.VerticalOffset) && (this.ExtentHeight > 0))
                {
                    m_mainScrollViewer.ScrollToVerticalOffset(offset);
                }
            }

            m_originalScrollChangedEventArgs = null;

            // In some situations, the Extent*Change event is received AFTER the
            // layout pass of the mainScrollViewer is done. Since the measure of the
            // mainScrollViewer uses the SynchronizedScrollViewer Extent size, we must
            // call InvalidateMeasure on the mainScrollViewer to ensure it is correctly
            // layouted
            if (invalidateMainScrollViewerMeasure)
            {
                m_mainScrollViewer.InvalidateMeasure();
            }
        }
Example #23
0
        public ScrollGallery(ScrollOrientation orientation = ScrollOrientation.Vertical)
        {
            _orientation = orientation;
            var root = new Grid();

            root.RowDefinitions.Add(new RowDefinition()
            {
                Height = GridLength.Auto
            });
            root.RowDefinitions.Add(new RowDefinition()
            {
                Height = GridLength.Auto
            });
            root.RowDefinitions.Add(new RowDefinition()
            {
                Height = GridLength.Auto
            });
            root.RowDefinitions.Add(new RowDefinition()
            {
                Height = GridLength.Auto
            });
            root.RowDefinitions.Add(new RowDefinition());

            var btnStack1 = new StackLayout {
                Orientation = StackOrientation.Horizontal
            };
            var btnStack2 = new StackLayout {
                Orientation = StackOrientation.Horizontal
            };
            var btnStack3 = new StackLayout {
                Orientation = StackOrientation.Horizontal
            };

            var btn = new Button {
                Text = "Scroll to 100"
            };
            var btn4 = new Button {
                Text = "Scroll to 100 no anim"
            };
            var btn1 = new Button {
                Text = "Start"
            };
            var btn2 = new Button {
                Text = "Center"
            };
            var btn3 = new Button {
                Text = "End"
            };
            var btn7 = new Button {
                Text = "Toggle Scroll Bar Visibility", WidthRequest = 120
            };
            var btn6 = new Button {
                Text = "MakeVisible", HorizontalOptions = LayoutOptions.CenterAndExpand, BackgroundColor = Color.Accent
            };
            var btn8 = new Button {
                Text = "Toggle Orientation", WidthRequest = 120
            };
            var btn9 = new Button {
                Text = "Default Scroll Bar Visibility", WidthRequest = 120
            };

            var labelStack = new StackLayout {
                Orientation = StackOrientation.Horizontal
            };
            var label = new Label {
                Text = string.Format("X: {0}, Y: {1}", 0, 0)
            };
            var scrollStatusLabel = new Label {
                Text = string.Empty
            };

            root.Children.Add(labelStack);
            root.Children.Add(btnStack1);
            root.Children.Add(btnStack2);
            root.Children.Add(btnStack3);

            btnStack1.Children.Add(btn1);
            btnStack1.Children.Add(btn2);
            btnStack1.Children.Add(btn3);

            btnStack2.Children.Add(btn);
            btnStack2.Children.Add(btn4);

            btnStack3.Children.Add(btn7);
            btnStack3.Children.Add(btn9);
            btnStack3.Children.Add(btn8);

            labelStack.Children.Add(label);
            labelStack.Children.Add(scrollStatusLabel);

            Grid.SetRow(btnStack1, 1);
            Grid.SetRow(btnStack2, 2);
            Grid.SetRow(btnStack3, 3);

            var grid = new Grid();

            grid.RowDefinitions.Add(new RowDefinition {
                Height = GridLength.Auto
            });
            grid.RowDefinitions.Add(new RowDefinition());
            _stack = new StackLayout();
            Grid.SetRow(_stack, 1);
            grid.Children.Add(btn6);
            grid.Children.Add(_stack);
            _scrollview = new ScrollView
            {
                AutomationId    = "thescroller",
                BackgroundColor = Color.Aqua,
                Content         = grid
            };
            root.Children.Add(_scrollview);
            Grid.SetRow(_scrollview, 4);

            _scrollview.Scrolled += (object sender, ScrolledEventArgs e) => {
                label.Text = string.Format("X: {0}, Y: {1}", e.ScrollX, e.ScrollY);
            };

            btn.Clicked += async(object sender, EventArgs e) => {
                scrollStatusLabel.Text = "scrolling";
                switch (orientation)
                {
                case ScrollOrientation.Horizontal:
                    await _scrollview.ScrollToAsync(100, 0, true);

                    break;

                case ScrollOrientation.Vertical:
                    await _scrollview.ScrollToAsync(0, 100, true);

                    break;

                case ScrollOrientation.Both:
                    await _scrollview.ScrollToAsync(100, 100, true);

                    break;
                }
                scrollStatusLabel.Text = "completed";
            };
            btn4.Clicked += async(object sender, EventArgs e) => {
                switch (orientation)
                {
                case ScrollOrientation.Horizontal:
                    await _scrollview.ScrollToAsync(100, 0, false);

                    break;

                case ScrollOrientation.Vertical:
                    await _scrollview.ScrollToAsync(0, 100, false);

                    break;

                case ScrollOrientation.Both:
                    await _scrollview.ScrollToAsync(100, 100, true);

                    break;
                }
            };

            btn1.Clicked += async(object sender, EventArgs e) => {
                await _scrollview.ScrollToAsync(_toNavigateTo, ScrollToPosition.Start, true);
            };
            btn2.Clicked += async(object sender, EventArgs e) => {
                await _scrollview.ScrollToAsync(_toNavigateTo, ScrollToPosition.Center, true);
            };
            btn3.Clicked += async(object sender, EventArgs e) => {
                await _scrollview.ScrollToAsync(_toNavigateTo, ScrollToPosition.End, true);
            };
            btn6.Clicked += async(object sender, EventArgs e) => {
                await _scrollview.ScrollToAsync(_toNavigateTo, ScrollToPosition.MakeVisible, true);
            };
            btn7.Clicked += (object sender, EventArgs e) =>
            {
                if (_scrollview.VerticalScrollBarVisibility == ScrollBarVisibility.Always ||
                    _scrollview.VerticalScrollBarVisibility == ScrollBarVisibility.Default)
                {
                    _scrollview.VerticalScrollBarVisibility   = ScrollBarVisibility.Never;
                    _scrollview.HorizontalScrollBarVisibility = ScrollBarVisibility.Never;
                }
                else
                {
                    _scrollview.VerticalScrollBarVisibility   = ScrollBarVisibility.Always;
                    _scrollview.HorizontalScrollBarVisibility = ScrollBarVisibility.Always;
                }
            };

            btn8.Clicked += (object sender, EventArgs e) =>
            {
                if (_scrollview.Orientation == ScrollOrientation.Horizontal)
                {
                    _scrollview.Orientation = ScrollOrientation.Vertical;
                }
                else
                {
                    _scrollview.Orientation = ScrollOrientation.Horizontal;
                }
            };

            btn9.Clicked += (object sender, EventArgs e) =>
            {
                _scrollview.VerticalScrollBarVisibility   = ScrollBarVisibility.Default;
                _scrollview.HorizontalScrollBarVisibility = ScrollBarVisibility.Default;
            };

            _stack.Padding = new Size(20, 60);

            PopulateStack(_stack);

            _scrollview.Orientation = _orientation;

            if (orientation == ScrollOrientation.Horizontal || orientation == ScrollOrientation.Both)
            {
                _stack.Orientation = StackOrientation.Horizontal;
            }

            if (orientation == ScrollOrientation.Both)
            {
                var stack2 = new StackLayout();
                PopulateStack(stack2);
                _stack.Children.Add(stack2);
            }

            Content = root;
        }
 public ScrollEventArgs(ScrollEventType type, int newValue, ScrollOrientation scroll)
 {
     _scrollType        = type;
     NewValue           = newValue;
     _scrollOrientation = scroll;
 }
Example #25
0
 public static ScrollView Orientation(this ScrollView scrollView, ScrollOrientation orientation)
 {
     scrollView.Orientation = orientation;
     return(scrollView);
 }
        private void WmOnScroll(ref System.Windows.Forms.Message m, int oldValue, int value, ScrollOrientation scrollOrientation)
        {
            var type = (ScrollEventType)NativeMethods.Util.LOWORD(m.WParam);

            if (type != ScrollEventType.EndScroll)
                OnScroll(new ScrollEventArgs(type, oldValue, value, scrollOrientation));
        }
Example #27
0
 private static int ScrollActionIndex(ScrollEventType type, ScrollOrientation orientation, int sign)
 => (type.HasFlag(ScrollEventType.SmallDecrement)        ? 4 : 0)
 + ((orientation == ScrollOrientation.HorizontalScroll) ? 2 : 0)
 + ((sign == +1)                                        ? 1 : 0);
Example #28
0
 public ScrollBar(Control ctrl, ScrollOrientation orientation)
 {
     this.TargetControl = ctrl;
     this.Orientation   = orientation;
     Update();
 }
Example #29
0
 public static void ScrollPanel(this IScrollableControl @this, ScrollEventType type,
                                ScrollOrientation orientation, int sign)
 => ScrollActions[ScrollActionIndex(type, orientation, sign)](@this);
Example #30
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: public LoadingLayout(android.content.Context context, final PullToRefresh.PullMode mode, final PullToRefresh.ScrollOrientation scrollDirection, android.content.res.TypedArray attrs)
        public LoadingLayout(Context context, PullMode mode, ScrollOrientation scrollDirection, TypedArray attrs) : base(context)
        {
            mMode            = mode;
            mScrollDirection = scrollDirection;

            switch (scrollDirection)
            {
            case ScrollOrientation.HORIZONTAL:
                LayoutInflater.From(context).Inflate(Resource.Layout.pull_to_refresh_header_horizontal, this);
                break;

            case ScrollOrientation.VERTICAL:
            default:
                LayoutInflater.From(context).Inflate(Resource.Layout.pull_to_refresh_header_vertical, this);
                break;
            }

            mInnerLayout    = (FrameLayout)FindViewById(Resource.Id.fl_inner);
            mHeaderText     = (TextView)mInnerLayout.FindViewById(Resource.Id.pull_to_refresh_text);
            mHeaderProgress = (ProgressBar)mInnerLayout.FindViewById(Resource.Id.pull_to_refresh_progress);
            mSubHeaderText  = (TextView)mInnerLayout.FindViewById(Resource.Id.pull_to_refresh_sub_text);
            mHeaderImage    = (ImageView)mInnerLayout.FindViewById(Resource.Id.pull_to_refresh_image);

            LayoutParams lp = (LayoutParams)mInnerLayout.LayoutParameters;

            switch (mode)
            {
            case PullMode.PULL_FROM_END:
                lp.Gravity = scrollDirection == ScrollOrientation.VERTICAL ? GravityFlags.Top : GravityFlags.Left;

                // Load in labels
                mPullLabel       = context.GetString(Resource.String.pull_to_refresh_pull_label);
                mRefreshingLabel = context.GetString(Resource.String.pull_to_refresh_refreshing_label);
                mReleaseLabel    = context.GetString(Resource.String.pull_to_refresh_release_label);
                break;

            case PullMode.PULL_FROM_START:
            default:
                lp.Gravity = scrollDirection == ScrollOrientation.VERTICAL ? GravityFlags.Bottom : GravityFlags.Right;

                // Load in labels
                mPullLabel       = context.GetString(Resource.String.pull_to_refresh_pull_label);
                mRefreshingLabel = context.GetString(Resource.String.pull_to_refresh_refreshing_label);
                mReleaseLabel    = context.GetString(Resource.String.pull_to_refresh_release_label);
                break;
            }

            if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrHeaderBackground))
            {
                Drawable background = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrHeaderBackground);
                if (null != background)
                {
                    ViewCompat.setBackground(this, background);
                }
            }

            if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrHeaderTextAppearance))
            {
                TypedValue styleID = new TypedValue();
                attrs.GetValue(Resource.Styleable.PullToRefresh_ptrHeaderTextAppearance, styleID);
                TextAppearance = styleID.Data;
            }
            if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrSubHeaderTextAppearance))
            {
                TypedValue styleID = new TypedValue();
                attrs.GetValue(Resource.Styleable.PullToRefresh_ptrSubHeaderTextAppearance, styleID);
                SubTextAppearance = styleID.Data;
            }

            // Text Color attrs need to be set after TextAppearance attrs
            if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrHeaderTextColor))
            {
                ColorStateList colors = attrs.GetColorStateList(Resource.Styleable.PullToRefresh_ptrHeaderTextColor);
                if (null != colors)
                {
                    TextColor = colors;
                }
            }
            if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrHeaderSubTextColor))
            {
                ColorStateList colors = attrs.GetColorStateList(Resource.Styleable.PullToRefresh_ptrHeaderSubTextColor);
                if (null != colors)
                {
                    SubTextColor = colors;
                }
            }

            // Try and get defined drawable from Attrs
            Drawable imageDrawable = null;

            if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawable))
            {
                imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawable);
            }

            // Check Specific Drawable from Attrs, these overrite the generic
            // drawable attr above
            switch (mode)
            {
            case PullMode.PULL_FROM_START:
            default:
                if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawableStart))
                {
                    imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawableStart);
                }
                else if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawableTop))
                {
                    Utils.warnDeprecation("ptrDrawableTop", "ptrDrawableStart");
                    imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawableTop);
                }
                break;

            case PullMode.PULL_FROM_END:
                if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawableEnd))
                {
                    imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawableEnd);
                }
                else if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawableBottom))
                {
                    Utils.warnDeprecation("ptrDrawableBottom", "ptrDrawableEnd");
                    imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawableBottom);
                }
                break;
            }

            // If we don't have a user defined drawable, load the default
            if (null == imageDrawable)
            {
                imageDrawable = context.Resources.GetDrawable(DefaultDrawableResId);
            }

            // Set Drawable, and save width/height
            LoadingDrawable = imageDrawable;

            reset();
        }
Example #31
0
        private ScrollEventArgs BuildScrollEventArgs(
            ScrollProperties scrollProperties,
            ScrollEventType scrollEventType,
            IntPtr wParam,
            ScrollOrientation scrollOrientation)
        {
            var oldPos   = scrollProperties.Value;
            int?delta    = null;
            int?exactPos = null;

            switch (scrollEventType)
            {
            case ScrollEventType.SmallDecrement:
                delta = -scrollProperties.SmallChange;
                break;

            case ScrollEventType.SmallIncrement:
                delta = scrollProperties.SmallChange;
                break;

            case ScrollEventType.LargeDecrement:
                delta = -scrollProperties.LargeChange;
                break;

            case ScrollEventType.LargeIncrement:
                delta = scrollProperties.LargeChange;
                break;

            case ScrollEventType.ThumbPosition:
                exactPos = HiWord((int)wParam);
                break;

            case ScrollEventType.ThumbTrack:
                exactPos = HiWord((int)wParam);
                break;

            case ScrollEventType.First:
                exactPos = scrollProperties.Minimum;
                break;

            case ScrollEventType.Last:
                exactPos = scrollProperties.Maximum;
                break;
            }

            if (!delta.HasValue && !exactPos.HasValue)
            {
                return(null);
            }

            var newPos = oldPos;

            if (delta.HasValue)
            {
                newPos = oldPos + delta.Value;
            }

            if (exactPos.HasValue)
            {
                newPos = exactPos.Value;
            }

            if (newPos < scrollProperties.Minimum)
            {
                newPos = scrollProperties.Minimum;
            }

            if (newPos > scrollProperties.Maximum)
            {
                newPos = scrollProperties.Maximum;
            }

            if (oldPos == newPos)
            {
                return(null);
            }
            else
            {
                if (newPos > scrollProperties.Maximum - 9)
                {
                    newPos = scrollProperties.Maximum - 9;
                }

                scrollProperties.Value = newPos;
                var args = new ScrollEventArgs(scrollEventType, oldPos, newPos, scrollOrientation);
                return(args);
            }
        }
Example #32
0
 /// <include file='doc\ScrollEvent.uex' path='docs/doc[@for="ScrollEventArgs.ScrollEventArgs1"]/*' />
 /// <devdoc>
 ///    <para>
 ///       Initializes a new instance of the <see cref='System.Windows.Forms.ScrollEventArgs'/>class.
 ///
 ///    </para>
 /// </devdoc>
 public ScrollEventArgs(ScrollEventType type, int newValue, ScrollOrientation scroll)
 {
     this.type              = type;
     this.newValue          = newValue;
     this.scrollOrientation = scroll;
 }
Example #33
0
 /// <include file='doc\ScrollEvent.uex' path='docs/doc[@for="ScrollEventArgs.ScrollEventArgs1"]/*' />
 /// <devdoc>
 ///    <para>
 ///       Initializes a new instance of the <see cref='System.Windows.Forms.ScrollEventArgs'/>class.
 ///       
 ///    </para>
 /// </devdoc>
 public ScrollEventArgs(ScrollEventType type, int newValue, ScrollOrientation scroll) {
     this.type = type;
     this.newValue = newValue;
     this.scrollOrientation = scroll;
 }
Example #34
0
        /// <summary>
        /// Refresh the ContainerVisual or ContainerElement
        /// </summary>
        /// <returns>Return true when the container is refreshed</returns>
        private bool RefreshContainerTile(double width, double height, double imageWidth, double imageHeight, ScrollOrientation orientation)
        {
            if (_isImageSourceLoaded == false || _isRootElementSizeChanged == false)
            {
                return(false);
            }

            double numberSpriteToInstantiate = 0;

            int numberImagePerColumn = 1;
            int numberImagePerRow    = 1;

            int offsetHorizontalAlignment = 0;
            int offsetVerticalAlignment   = 0;

            var clip = new RectangleGeometry {
                Rect = new Rect(0, 0, width, height)
            };

            _rootElement.Clip = clip;

            var imageAlignment = ImageAlignment;

            switch (orientation)
            {
            case ScrollOrientation.Horizontal:
                numberImagePerColumn = (int)Math.Ceiling(width / imageWidth) + 1;

                if (imageAlignment == ImageAlignment.Top || imageAlignment == ImageAlignment.Bottom)
                {
                    numberImagePerRow = 1;

                    if (imageAlignment == ImageAlignment.Bottom)
                    {
                        offsetHorizontalAlignment = (int)(height - imageHeight);
                    }
                }
                else
                {
                    numberImagePerRow = (int)Math.Ceiling(height / imageHeight);
                }

                numberSpriteToInstantiate = numberImagePerColumn * numberImagePerRow;
                break;

            case ScrollOrientation.Vertical:
                numberImagePerRow = (int)Math.Ceiling(height / imageHeight) + 1;

                if (imageAlignment == ImageAlignment.Left || imageAlignment == ImageAlignment.Right)
                {
                    numberImagePerColumn = 1;

                    if (ImageAlignment == ImageAlignment.Right)
                    {
                        offsetVerticalAlignment = (int)(width - imageWidth);
                    }
                }
                else
                {
                    numberImagePerColumn = (int)Math.Ceiling(width / imageWidth);
                }

                numberSpriteToInstantiate = numberImagePerColumn * numberImagePerRow;

                break;

            case ScrollOrientation.Both:
                numberImagePerColumn      = (int)Math.Ceiling(width / imageWidth) + 1;
                numberImagePerRow         = (int)(Math.Ceiling(height / imageHeight) + 1);
                numberSpriteToInstantiate = numberImagePerColumn * numberImagePerRow;
                break;
            }

            var count = _compositionChildren.Count;

            // instantiate all elements not created yet
            for (int x = 0; x < numberSpriteToInstantiate - count; x++)
            {
                var sprite = _containerVisual.Compositor.CreateSpriteVisual();
                _containerVisual.Children.InsertAtTop(sprite);
                _compositionChildren.Add(sprite);
            }

            // remove elements not used now
            for (int x = 0; x < count - numberSpriteToInstantiate; x++)
            {
                var element = _containerVisual.Children.FirstOrDefault() as SpriteVisual;
                _containerVisual.Children.Remove(element);
                _compositionChildren.Remove(element);
            }

            // Change positions+brush for all actives elements
            for (int y = 0; y < numberImagePerRow; y++)
            {
                for (int x = 0; x < numberImagePerColumn; x++)
                {
                    int index = (y * numberImagePerColumn) + x;

                    var sprite = _compositionChildren[index];
                    sprite.Brush  = _brushVisual;
                    sprite.Offset = new Vector3((float)((x * imageWidth) + offsetVerticalAlignment), (float)((y * imageHeight) + offsetHorizontalAlignment), 0);
                    sprite.Size   = new Vector2((float)imageWidth, (float)imageHeight);
                }
            }

            return(true);
        }
Example #35
0
 public bool GetScrollEnabled(ScrollOrientation orientation)
 {
     switch (orientation) {
         case ScrollOrientation.HorizontalScroll:
             return _canScrollH;
         case ScrollOrientation.VerticalScroll:
             return _canScrollV;
     }
     return false;
 }
Example #36
0
        /// <summary>
        /// 更新标签位置
        /// </summary>
        private void UpdateTabPosition()
        {
            int row = 0, col = 0, colSpan = 1, rowSpan = 1;
            ScrollOrientation orientation = ScrollOrientation.Horizontal;
            StackOrientation  orientation2 = StackOrientation.Horizontal;

            switch (this.TabPosition)
            {
            case TabViewPositions.Top:
                row          = 0;
                col          = 0;
                colSpan      = 3;
                rowSpan      = 1;
                orientation  = ScrollOrientation.Horizontal;
                orientation2 = StackOrientation.Horizontal;
                break;

            case TabViewPositions.Bottom:
                row          = 2;
                col          = 0;
                colSpan      = 3;
                rowSpan      = 1;
                orientation  = ScrollOrientation.Horizontal;
                orientation2 = StackOrientation.Horizontal;
                break;

            case TabViewPositions.Left:
                row          = 0;
                col          = 0;
                rowSpan      = 3;
                colSpan      = 1;
                orientation  = ScrollOrientation.Vertical;
                orientation2 = StackOrientation.Vertical;
                break;

            case TabViewPositions.Right:
                row          = 0;
                col          = 2;
                rowSpan      = 3;
                colSpan      = 1;
                orientation  = ScrollOrientation.Vertical;
                orientation2 = StackOrientation.Vertical;
                break;
            }

            this.TabBarScroller.Orientation       = orientation;
            this.TabBarScroller.HorizontalOptions = LayoutOptions.Fill;
            this.TabBarScroller.VerticalOptions   = LayoutOptions.Fill;

            this.TabBarInner.Orientation = orientation2;
            if (this.TabBarInner.Orientation == StackOrientation.Horizontal)
            {
                this.TabBarInner.HorizontalOptions = LayoutOptions.Center;
                this.TabBarInner.VerticalOptions   = LayoutOptions.Center;
            }
            else
            {
                this.TabBarInner.HorizontalOptions = LayoutOptions.Center;
                this.TabBarInner.VerticalOptions   = LayoutOptions.Start;
            }

            Grid.SetRow(this.TabBar, row);
            Grid.SetColumn(this.TabBar, col);
            Grid.SetRowSpan(this.TabBar, rowSpan);
            Grid.SetColumnSpan(this.TabBar, colSpan);
        }
Example #37
0
 public int GetScrollSmallChange(ScrollOrientation orientation)
 {
     switch (orientation) {
         case ScrollOrientation.HorizontalScroll:
             return _scrollSmChangeH;
         case ScrollOrientation.VerticalScroll:
             return _scrollSmChangeV;
     }
     return 0;
 }
Example #38
0
 public int GetScrollValue(ScrollOrientation orientation)
 {
     switch (orientation) {
         case ScrollOrientation.HorizontalScroll:
             return _scrollH;
         case ScrollOrientation.VerticalScroll:
             return _scrollV;
     }
     return 0;
 }
Example #39
0
        public void ScrollTo(ScrollOrientation orientation, int value)
        {
            int oldVal = 0;

            switch (orientation) {
                case ScrollOrientation.HorizontalScroll:
                    if (!_canScrollH) {
                        return;
                    }

                    oldVal = _scrollH;
                    _scrollH = value;
                    break;

                case ScrollOrientation.VerticalScroll:
                    if (!_canScrollV) {
                        return;
                    }

                    oldVal = _scrollV;
                    _scrollV = value;
                    break;
            }

            OnScroll(new ScrollEventArgs(ScrollEventType.ThumbPosition, oldVal, value, orientation));
        }
Example #40
0
 /// <summary>
 ///   Sets scrollbar properties.
 /// </summary>
 /// <param name="scrollbar">The scrollbar.</param>
 /// <param name="scrollInfo">The scrollbar properties.</param>
 /// <param name="refresh">
 ///   if set to <c>true</c> the scrollbar will be repainted.
 /// </param>
 /// <returns></returns>
 // ReSharper disable UnusedMethodReturnValue.Local
 private int SetScrollInfo(ScrollOrientation scrollbar, NativeMethods.SCROLLINFO scrollInfo, bool refresh) // ReSharper restore UnusedMethodReturnValue.Local
 {
     return(NativeMethods.SetScrollInfo(this.Handle, (int)scrollbar, scrollInfo, refresh));
 }
Example #41
0
        public void SetScrollSmallChange(ScrollOrientation orientation, int value)
        {
            switch (orientation) {
                case ScrollOrientation.HorizontalScroll:
                    _scrollSmChangeH = value;
                    break;
                case ScrollOrientation.VerticalScroll:
                    _scrollSmChangeV = value;
                    break;
            }

            OnScrollPropertyChanged();
        }
        private void OnMainScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            if (e.OriginalSource != m_mainScrollViewer)
            {
                return;
            }

            if (m_deferScrollChange)
            {
                return;
            }

            ScrollOrientation orientation = this.ScrollOrientation;
            bool limitScrolling           = this.LimitScrolling;

            if ((orientation & ScrollOrientation.Horizontal) == ScrollOrientation.Horizontal)
            {
                // If the Extent is 0, there is no reason to update
                // the main ScrollViewer offset since this means there
                // are no children
                if (this.ExtentWidth == 0)
                {
                    return;
                }

                double offset = (limitScrolling)
          ? System.Math.Min(e.HorizontalOffset, this.ExtentWidth - this.ViewportWidth)
          : e.HorizontalOffset;

                if (offset != this.HorizontalOffset)
                {
                    // We keep the original ScrollChangedEventArgs because when we'll update
                    // our offset, it might be less than what was asked in the first place. Even
                    // if this doesn't make sense to us, it might be ok for the m_mainScrollViewer
                    // to scroll to that value. Since changing our offset will trigger the OnScrollChanged
                    // that will update the m_mainScrollViewer, we want to changer it's offset to
                    // the right value.
                    m_originalScrollChangedEventArgs = e;
                    this.ScrollToHorizontalOffset(offset);
                }
            }

            if ((orientation & ScrollOrientation.Vertical) == ScrollOrientation.Vertical)
            {
                // If the Extent is 0, there is no reason to update
                // the main ScrollViewer offset since this means there
                // are no children
                if (this.ExtentHeight == 0)
                {
                    return;
                }

                double offset = (limitScrolling)
          ? System.Math.Min(e.VerticalOffset, this.ExtentHeight - this.ViewportHeight)
          : e.VerticalOffset;

                if (offset != this.VerticalOffset)
                {
                    // We keep the original ScrollChangedEventArgs because when we'll update
                    // our offset, it might be less than what was asked in the first place. Even
                    // if this doesn't make sense to us, it might be ok for the m_mainScrollViewer
                    // to scroll to that value. Since changing our offset will trigger the OnScrollChanged
                    // that will update the m_mainScrollViewer, we want to changer it's offset to
                    // the right value.
                    m_originalScrollChangedEventArgs = e;
                    this.ScrollToVerticalOffset(offset);
                }
            }
        }
        /// <summary>TODO</summary>
        public void ScrollPanel(ScrollEventType type, ScrollOrientation orientation, int sign)
        {
            if (sign != 0)
            {
                ScrollProperties scroll;
                Func<Point, int, int, Point> func;
                if (orientation == ScrollOrientation.VerticalScroll)
                {
                    scroll = VerticalScroll;
                    func = (p, sgn, stp) => new Point(-p.X, -p.Y + stp * sgn);
                }
                else
                {
                    scroll = HorizontalScroll;
                    func = (p, sgn, stp) => new Point(-p.X + stp * sgn, -p.Y);
                }

                var step = type.HasFlag(ScrollEventType.LargeIncrement) || type.HasFlag(ScrollEventType.LargeDecrement)
                         ? scroll.LargeChange
                         : scroll.SmallChange;
                var oldValue = scroll.Value;
                AutoScrollPosition = func(AutoScrollPosition, sign, step);
                OnScroll(new ScrollEventArgs(type, oldValue, scroll.Value, orientation));
            }
        }
 private void OnScroll(ScrollEventType scrollEventType, int oldValue, int newValue, ScrollOrientation orientation)
 {
     ScrollEventArgs se = new ScrollEventArgs(scrollEventType, oldValue, newValue, orientation);
     OnScroll(se);
     RefreshByCurrentPos(oldValue, newValue);
     if (ScrollOrientation.VerticalScroll == orientation)
     {
         if (se.NewValue != newValue)
         {
             try
             {
                 this.dataGridViewState2[DATAGRIDVIEWSTATE2_stopRaisingVerticalScroll] = true;
                 int rowIndex = this.Rows.GetFirstRow(DataGridViewElementStates.Visible, DataGridViewElementStates.Frozen);
                 int rowIndexPrevious = rowIndex;
                 newValue = se.NewValue;
                 while (rowIndex != -1 && newValue > 0)
                 {
                     rowIndexPrevious = rowIndex;
                     rowIndex = this.Rows.GetNextRow(rowIndex, DataGridViewElementStates.Visible);
                     newValue--;
                 }
                 if (rowIndex != -1)
                 {
                     rowIndexPrevious = rowIndex;
                 }
                 if (rowIndexPrevious != -1)
                 {
                     this.FirstDisplayedScrollingRowIndex = rowIndexPrevious;
                 }
             }
             finally
             {
                 this.dataGridViewState2[DATAGRIDVIEWSTATE2_stopRaisingVerticalScroll] = false;
             }
         }
     }
     else
     {
         if (se.NewValue != newValue)
         {
             try
             {
                 this.dataGridViewState2[DATAGRIDVIEWSTATE2_stopRaisingHorizontalScroll] = true;
                 this.HorizontalOffset = se.NewValue;
             }
             finally
             {
                 this.dataGridViewState2[DATAGRIDVIEWSTATE2_stopRaisingHorizontalScroll] = false;
             }
         }
     }
 }
        int WheelPanelDetail(ScrollOrientation orientation, ScrollProperties scroll, int delta,
          Func<Point, int, Point> newAutoScroll, int remainder)
        {
            if (scroll == null) throw new ArgumentNullException("scroll");
            if (newAutoScroll == null) throw new ArgumentNullException("newAutoScroll");
            const int mouseWheelDelta = 120;

            var scrollLines = SystemInformation.MouseWheelScrollLines;
            var steps = Math.Sign(delta) * ((Math.Abs(delta + remainder) * scrollLines) / mouseWheelDelta);
            remainder = Math.Sign(delta) * ((Math.Abs(delta + remainder) * scrollLines) % mouseWheelDelta);

            if (steps != 0)
            {
                var oldValue = scroll.Value;
                AutoScrollPosition = newAutoScroll(AutoScrollPosition, scroll.SmallChange * steps);
                OnScroll(new ScrollEventArgs(ScrollEventType.ThumbPosition, oldValue, scroll.Value, orientation));
            }
            return remainder;
        }
Example #46
0
        public void SetScrollValue(ScrollOrientation orientation, int value)
        {
            switch (orientation) {
                case ScrollOrientation.HorizontalScroll:
                    _scrollH = value;
                    break;
                case ScrollOrientation.VerticalScroll:
                    _scrollV = value;
                    break;
            }

            Invalidate();
        }
Example #47
0
 public ScrollEventArgs(ScrollEventType type, int oldValue, int newValue, ScrollOrientation scroll)
 {
     throw null;
 }
 void WheelPanel(ScrollOrientation orientation, int delta)
 {
     if (orientation == ScrollOrientation.VerticalScroll)
         mouseWheelVerticalRemainder = WheelPanelDetail(orientation, VerticalScroll, delta,
             (p, amount) => new Point(-p.X, -p.Y + amount), mouseWheelVerticalRemainder);
     else
         mouseWheelHorizontalRemainder = WheelPanelDetail(orientation, HorizontalScroll, delta,
             (p, amount) => new Point(-p.X + amount, -p.Y), mouseWheelHorizontalRemainder);
 }
        private void BuildGrid()
        {
            // Remove previously generated Grids
            if (this.Children != null && this.Children.Count != null && this.Children.Count != 0)
            {
                this.Children.Clear();
            }

            // In the case that ViewModels was previously non-null and Count > 0, the children
            // would have been cleared in the previous step, thus accommodating a return of 
            // ViewModels from non-null to null, hence needing to clear the display.
            if (this.ViewModels == null) return;

            // Initialisations
            double gridwidth = 0;
            double gridheight = 0;
            double autogridwidth = 0;
            double autogridheight = 0;
            double cellwidth = 0;
            double cellheight = 0;
            bool addStarRowDefinition = false;
            bool starRowDefinitionAdded = false;
            bool addStarColumnDefinition = false;
            bool starColumnDefinitionAdded = false;

            #region Primary Auto Grid UI component creation
            // Create a Grid backing grid
            // ToDo: Add DP ScrollGridBackgroundOpacity so that the ScrollGridBackground can have opacity
            var gridCapsule = new ContentView() { BackgroundColor = ScrollGridBackgroundColor };

            // Create the Auto Grid, within which all the cells will be added, one for each ViewModel in the ViewModel collection,
            // and blank cells for the overflow where total number of cells (rows * columns) is greater than the ViewModel count.
            var autoGrid = new Grid
            {
                ColumnSpacing = this.CellSpacing,
                RowSpacing = this.CellSpacing,
                BackgroundColor = Color.Transparent,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            // Put the Auto Grid inside a view whose own BackgroundColor and Opacity can be set.
            gridCapsule.Content = autoGrid;

            // Create empty RowDefinition and ColumnDefinition collections.
            autoGrid.RowDefinitions = new RowDefinitionCollection();
            autoGrid.ColumnDefinitions = new ColumnDefinitionCollection();

            // Add a scrollvew to cater for situations where the Auto Grid is either wider or taller than the control dimensions.
            // Also, add the grid capsule to the scrollview.
            ScrollView scrollView = new ScrollView
            {
                Orientation = _scrollViewOrientation,
                BackgroundColor = _controlBackgroundColor,
                Content = gridCapsule
            };
            #endregion

            #region Grid Metric Calculations
            // Make all the necessary grid metric calculations prior to building it
            // Either NumberOfRows > 0, or NumberOfColumns > 0
            // ViewModels is always > 0

            int viewModelCount = ViewModels.Count;
            int numberOfRows = NumberOfRows;
            int numberOfColumns = NumberOfColumns;
            int numberOfCells = 0;

            if (NumberOfRows == 0 && NumberOfColumns == 0) return;

            if (NumberOfRows >= NumberOfColumns)
            {
                // Calculate columns given fixed row-count and a number of ViewModels
                var mod = viewModelCount % numberOfRows;
                var diff = numberOfRows - mod;
                if (mod != 0)
                {
                    numberOfColumns = ((viewModelCount + diff) / numberOfRows);
                }
                else
                {
                    numberOfColumns = (viewModelCount / numberOfRows);
                }
                _scrollViewOrientation = ScrollOrientation.Horizontal;
                numberOfCells = NumberOfRows * numberOfColumns;
            }
            else
            {
                // Calculate rows given fixed column-count and a number of ViewModels

                var mod = viewModelCount % numberOfColumns;
                var diff = NumberOfColumns - mod;
                if (mod != 0)
                {
                    numberOfRows = ((viewModelCount + diff) / numberOfColumns);
                }
                else
                {
                    numberOfRows = (viewModelCount / numberOfColumns);
                }
                _scrollViewOrientation = ScrollOrientation.Vertical;
                numberOfCells = NumberOfColumns * numberOfRows;
            }
            #endregion

            #region RowDefinition and ColumnDefintion creation
            for (int columns = 0; columns < numberOfColumns; columns++)
            {
                // Create Column Definitions
                autoGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
            }

            for (int rows = 0; rows < numberOfRows; rows++)
            {
                // Create Row Definitions
                autoGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
            }
            #endregion

            #region Cell Population
            // Sequentialy create and set some UI in each cell of the Grid up to the number of ViewModels in the ViewModel collection.
            // a. Each Cell will have a View, a Tap Gesture Recogniser attached to the View, and a ViewModel attached to the View as an Attached Property.
            // b. Each View Model carries a ViewOperator func that has been passed into it to build the View that corresponds to the View Model.
            // c. Each View Model also has a ViewModelsOperator (plural!) that has been passed into it and which, in the Tap Gesture Recogniser 'Tapped' event, 
            // is capable of acting upon every ViewModel in the collection (and it can differentiate between the current ('tapped') View Model and the others).
            // d. Every View Model is also capable of carrying a Dto that corresponds to the model that the Cell represents. This, of course, can be acted upon by the 
            // ViewModelsOperator when the Cell is tapped.
            int column = 0;
            int row = 0;
            for (int i = 0; i < numberOfCells; i++)
            {
                View view = null;

                if (i < viewModelCount)
                {
                    // Create a Tap Gesture Recogniser
                    var tapGesturer = new TapGestureRecognizer();
                    tapGesturer.Tapped += (s, e) =>
                    {
                        #region Respond to Tapped Event
                        Debug.WriteLine("Xamtastic: AutoGridView tapped! (Com.Xamtastic.Patterns.ViewModelFactory.Views)");
                        var clickedUIItem = (View)s;

                        // Get the attached ViewModel so that it's Id can be used later
                        var clickedItemAttachedViewModel = (Boffin)clickedUIItem.GetValue(Attached.ViewModelProperty);

                        // Cycle through every cell and subject every View and it's ViewModel, to the items own ViewModel operator (Func).
                        foreach (var item in autoGrid.Children)
                        {
                            var attachedViewModel = (Boffin)item.GetValue(Attached.ViewModelProperty);
                            if (attachedViewModel != null)
                            {
                                attachedViewModel.Response = attachedViewModel.ViewModelOperator(attachedViewModel, clickedItemAttachedViewModel.Id);
                            }
                        }

                        for (int x = 0; x < ViewModels.Count; x++)
                        {
                            if (ViewModels[x].Equals(clickedItemAttachedViewModel))
                            {
                                ViewModels[x] = clickedItemAttachedViewModel;
                            }
                        }
                        #endregion
                    };

                    // Get a View for the ViewModel
                    if (ViewModels[i].ViewOperator != null)
                    {
                        view = ViewModels[i].ViewOperator(ViewModels[i]);
                    }
                    else if (ViewModels[i].ViewType != null)
                    {
                        view = (View)Activator.CreateInstance(ViewModels[i].ViewType);
                        ((IBindableObjectView)view).ViewModel = ViewModels[i];
                    }
                    else
                    {
                        throw new Exception("Xamtastic Exception: Both ViewOperator and ViewType are null in AutoGridView (Com.Xamtastic.Patterns.ViewModelFactory.Views).");
                    }

                    // Add the Tap Gesture Recogniser to the View
                    view.GestureRecognizers.Add(tapGesturer);
                    // Attach the ViewModel to the View as an Attached Property
                    view.SetValue(Attached.ViewModelProperty, ViewModels[i]);
                }
                else
                {
                    // For cells that don't have a ViewModel (i.e. for when ViewModels.Count() is less than Rows * Columns)

                    // If a BlankViewOperator Func hasn't been provided to create a blank view, create a default BlankViewOperator Func
                    if (this.BlankViewOperator == null)
                    {
                        this.BlankViewOperator = (viewmodel) => { return new Grid { BackgroundColor = Color.Gray }; };
                    }
                    // Create a blank cell view
                    view = this.BlankViewOperator(null);
                }

                // Add the View to the Grid
                autoGrid.Children.Add(view);
                // Set the View to a specific Column and Row in the Grid
                Grid.SetColumn(view, column);
                Grid.SetRow(view, row);

                // Calculate the indexes of the next cell's column and row, for the next View
                if (NumberOfRows >= NumberOfColumns)
                {
                    if (row < (numberOfRows - 1))
                    {
                        row++;
                    }
                    else
                    {
                        row = 0;
                        column++;
                    }
                }
                else
                {
                    if (column < (numberOfColumns - 1))
                    {
                        column++;
                    }
                    else
                    {
                        column = 0;
                        row++;
                    }
                }
            }
            #endregion

            #region AutoGridView Primary Component Layout

            // First, add the ScrollView (which has the AutoGrid) to this view.
            this.Children.Add(
                scrollView,
                Constraint.RelativeToParent((parent) =>
                {
                    if (FitToGrid == false)
                    {   // If false, the ScrollView scrolls, if true, the whole grid will morph to the size of the control.
                        if (NumberOfRows >= NumberOfColumns) // i.e. horizontal scrolling as number of rows is fixed
                        {
                            // Calculate width of Grid, if Rows were fixed
                            gridwidth = numberOfColumns * ((parent.Height / numberOfRows) * (1 / CellQuotient));
                            autogridwidth = parent.Width;
                            autogridheight = parent.Height;
                            cellwidth = ((parent.Width / numberOfColumns) * (1 / CellQuotient));
                            autoGrid.WidthRequest = gridwidth;

                            #region Cater for when Cells do not occupy the whole grid width
                            // i.e. If the width of all the grid's columns would less than the width of the grid, add an additional column with width = star
                            ReassignHorizontalDefinitions(gridwidth, autogridwidth, cellwidth, ref addStarColumnDefinition, ref starColumnDefinitionAdded, autoGrid);
                            #endregion
                        }
                        else // i.e. vertical scrolling as number of columns is fixed
                        {
                            // Calculate height of Grid, if Columns were fixed
                            gridheight = numberOfRows * ((parent.Width / numberOfColumns) * CellQuotient);
                            autogridheight = parent.Height;
                            autogridwidth = parent.Width;
                            cellheight = ((parent.Width / numberOfColumns) * CellQuotient);
                            autoGrid.HeightRequest = gridheight;

                            #region Cater for when Cells do not occupy the whole grid height
                            // i.e. If the height of all the grid's rows would less than the height of the grid, add an additional row with height = star
                            ReassignVerticalDefinitions(gridheight, autogridheight, cellheight, ref addStarRowDefinition, ref starRowDefinitionAdded, autoGrid);
                            #endregion
                        }
                    }

                    return 0; // X = 0
                }),
                Constraint.RelativeToParent((parent) =>
                {
                    return 0; // Y = 0
                }),
                Constraint.RelativeToParent((parent) =>
                {
                    return parent.Width; // Width
                }),
                Constraint.RelativeToParent((parent) =>
                {
                    return parent.Height; // Height
                }));
            #endregion
        }
 /// <summary>
 ///   Sets scrollbar properties.
 /// </summary>
 /// <param name="scrollbar">The scrollbar.</param>
 /// <param name="scrollInfo">The scrollbar properties.</param>
 /// <param name="refresh">
 ///   if set to <c>true</c> the scrollbar will be repainted.
 /// </param>
 /// <returns></returns>
 // ReSharper disable UnusedMethodReturnValue.Local
 private int SetScrollInfo(ScrollOrientation scrollbar, NativeMethods.SCROLLINFO scrollInfo, bool refresh) // ReSharper restore UnusedMethodReturnValue.Local
 {
   return NativeMethods.SetScrollInfo(this.Handle, (int)scrollbar, scrollInfo, refresh);
 }
Example #51
0
 public static T Orientation <T>(this T scrollview, ScrollOrientation orientation) where T : IRxScrollView
 {
     scrollview.Orientation = orientation;
     return(scrollview);
 }
Example #52
0
 public MonitorScrollEventArgs(Display monitor, ScrollEventType type, int oldValue, int newValue, ScrollOrientation scroll)
     : base(type, oldValue, newValue, scroll)
 {
     this.monitor = monitor;
 }
Example #53
0
        /// <summary>
        /// Creation of an expression to manage modulo (positive and negative value)
        /// </summary>
        /// <param name="scrollviewer">The ScrollViewer to synchonized. A null value is valid</param>
        /// <param name="imageWidth">Width of the image</param>
        /// <param name="imageHeight">Height of the image</param>
        /// <param name="scrollOrientation">The ScrollOrientation</param>
        private void CreateModuloExpression(ScrollViewer scrollviewer, double imageWidth, double imageHeight, ScrollOrientation scrollOrientation)
        {
            if (Strategy == UIStrategy.PureXaml)
            {
                return;
            }

            if (_containerVisual == null)
            {
                return;
            }

            var compositor = _containerVisual.Compositor;

            // Setup the expression
            var expressionX = compositor.CreateExpressionAnimation();
            var expressionY = compositor.CreateExpressionAnimation();

            var propertyOffsetModulo = compositor.CreatePropertySet();

            propertyOffsetModulo.InsertScalar("imageWidth", (float)imageWidth);
            propertyOffsetModulo.InsertScalar("offsetX", (float)OffsetX);
            propertyOffsetModulo.InsertScalar("imageHeight", (float)imageHeight);
            propertyOffsetModulo.InsertScalar("offsetY", (float)OffsetY);
            propertyOffsetModulo.InsertScalar("speed", (float)ParallaxSpeedRatio);

            expressionX.SetReferenceParameter("p", propertyOffsetModulo);
            expressionY.SetReferenceParameter("p", propertyOffsetModulo);

            string expressionXString = null;
            string expressionYString = null;

            if (scrollviewer == null)
            {
                // expressions are create to simulate a positive and negative modulo with the size of the image and the offset
                expressionXString = "Ceil(p.offsetX) == 0 ? 0 : (Ceil(p.offsetX) < 0 ? -(Abs(Ceil(p.offsetX) - Ceil(Ceil(p.offsetX) / p.imageWidth) * p.imageWidth) % p.imageWidth) : -(p.imageWidth - (Ceil(p.offsetX) % p.imageWidth)))";
                expressionYString = "Ceil(p.offsetY) == 0 ? 0 : (Ceil(p.offsetY) < 0 ? -(Abs(Ceil(p.offsetY) - Ceil(Ceil(p.offsetY) / p.imageHeight) * p.imageHeight) % p.imageHeight) : -(p.imageHeight - (Ceil(p.offsetY) % p.imageHeight)))";
            }
            else
            {
                // expressions are create to simulate a positive and negative modulo with the size of the image and the offset and the ScrollViewer offset (Translation)
                var scrollProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollviewer);

                expressionX.SetReferenceParameter("s", scrollProperties);
                expressionY.SetReferenceParameter("s", scrollProperties);

                expressionXString = "Ceil((s.Translation.X * p.speed) + p.offsetX) == 0 ? 0 : (Ceil((s.Translation.X * p.speed) + p.offsetX) < 0 ? -(Abs(Ceil((s.Translation.X * p.speed) + p.offsetX) - Ceil(Ceil((s.Translation.X * p.speed) + p.offsetX) / p.imageWidth) * p.imageWidth) % p.imageWidth) : -(p.imageWidth - (Ceil((s.Translation.X * p.speed) + p.offsetX) % p.imageWidth)))";
                expressionYString = "Ceil((s.Translation.Y * p.speed) + p.offsetY) == 0 ? 0 : (Ceil((s.Translation.Y * p.speed) + p.offsetY) < 0 ? -(Abs(Ceil((s.Translation.Y * p.speed) + p.offsetY) - Ceil(Ceil((s.Translation.Y * p.speed) + p.offsetY) / p.imageHeight) * p.imageHeight) % p.imageHeight) : -(p.imageHeight - (Ceil((s.Translation.Y * p.speed) + p.offsetY) % p.imageHeight)))";
            }

            if (scrollOrientation == ScrollOrientation.Horizontal || scrollOrientation == ScrollOrientation.Both)
            {
                expressionX.Expression = expressionXString;

                if (scrollOrientation == ScrollOrientation.Horizontal)
                {
                    // In horizontal mode we never move the offset y
                    expressionY.Expression  = "0";
                    _containerVisual.Offset = new Vector3((float)OffsetY, 0, 0);
                }
            }

            if (scrollOrientation == ScrollOrientation.Vertical || scrollOrientation == ScrollOrientation.Both)
            {
                expressionY.Expression = expressionYString;

                if (scrollOrientation == ScrollOrientation.Vertical)
                {
                    // In vertical mode we never move the offset x
                    expressionX.Expression  = "0";
                    _containerVisual.Offset = new Vector3(0, (float)OffsetX, 0);
                }
            }

            _containerVisual.StopAnimation("Offset.X");
            _containerVisual.StopAnimation("Offset.Y");

            _containerVisual.StartAnimation("Offset.X", expressionX);
            _containerVisual.StartAnimation("Offset.Y", expressionY);

            _propertyOffsetModulo = propertyOffsetModulo;
        }
        /// <summary>
        ///   Set the given scrollbar's tracking position to the specified value
        /// </summary>
        /// <param name="scrollbar">The scrollbar.</param>
        /// <param name="value">The value.</param>
        protected virtual void ScrollTo(ScrollOrientation scrollbar, int value)
        {
            NativeMethods.SCROLLINFO oldInfo;

            oldInfo = this.GetScrollInfo(scrollbar);

            if (value > ((oldInfo.nMax - oldInfo.nMin) + 1) - oldInfo.nPage)
            {
                value = ((oldInfo.nMax - oldInfo.nMin) + 1) - oldInfo.nPage;
            }
            if (value < oldInfo.nMin)
            {
                value = oldInfo.nMin;
            }

            if (oldInfo.nPos != value)
            {
                NativeMethods.SCROLLINFO scrollInfo;

                scrollInfo = new NativeMethods.SCROLLINFO();
                scrollInfo.fMask = NativeMethods.SIF.SIF_POS;
                scrollInfo.nPos = value;
                this.SetScrollInfo(scrollbar, scrollInfo, true);

                this.OnScroll(new ScrollEventArgs(ScrollEventType.ThumbPosition, oldInfo.nPos, value, scrollbar));
            }
        }
 private void WmOnScroll(ref Message m, int oldValue, int value, ScrollOrientation scrollOrientation)
 {
     ScrollEventType type = (ScrollEventType) System.Windows.Forms.NativeMethods.Util.LOWORD(m.WParam);
     if (type != ScrollEventType.EndScroll)
     {
         ScrollEventArgs se = new ScrollEventArgs(type, oldValue, value, scrollOrientation);
         this.OnScroll(se);
     }
 }
 // ReSharper restore UnusedMethodReturnValue.Local
 /// <summary>
 ///   Sets scrollbar properties.
 /// </summary>
 /// <param name="scrollbar">The scrollbar.</param>
 /// <param name="scrollInfo">The scrollbar properties.</param>
 /// <param name="refresh">
 ///   if set to <c>true</c> the scrollbar will be repainted.
 /// </param>
 /// <returns></returns>
 // ReSharper disable UnusedMethodReturnValue.Local
 private int SetScrollInfo(ScrollOrientation scrollbar, NativeMethods.SCROLLINFO scrollInfo, bool refresh)
 {
     return NativeMethods.SetScrollInfo(this.Handle, (int)scrollbar, scrollInfo, refresh);
 }
Example #57
0
 public MonitorScrollEventArgs(Display monitor, ScrollEventType type, int oldValue, int newValue, ScrollOrientation scroll)
     : base(type, oldValue, newValue, scroll)
 {
     this.monitor = monitor;
 }