public void SetDisplayRectLocation_InvokeWithHandle_Success(bool autoScroll, int x, int y, Rectangle expectedDisplayRectangle, Rectangle expectedBounds)
        {
            var control = new SubScrollableControl
            {
                AutoScroll = autoScroll,
                ClientSize = new Size(70, 80)
            };

            // Without child.
            control.SetDisplayRectLocation(x, y);
            Assert.Equal(new Rectangle(0, 0, 70, 80), control.DisplayRectangle);
            Assert.Equal(Point.Empty, control.AutoScrollPosition);

            // With child.
            var child = new LargeControl();

            control.Controls.Add(child);
            Assert.Equal(new Rectangle(0, 0, 100, 150), child.Bounds);

            // With created handle.
            Assert.NotEqual(IntPtr.Zero, child.Handle);
            control.SetDisplayRectLocation(x, y);
            Assert.Equal(expectedDisplayRectangle, control.DisplayRectangle);
            Assert.Equal(expectedDisplayRectangle.Location, control.AutoScrollPosition);
            Assert.Equal(expectedBounds, child.Bounds);
        }
Example #2
0
        public void SetDisplayRectLocation_Invoke_Success(bool autoScroll, int width, int height, int scrollX, int scrollY, Point expectedDisplayRectangleLocation, Size expectedDisplayRectangleSize)
        {
            var control = new SubScrollableControl
            {
                AutoScroll = autoScroll,
                ClientSize = new Size(width, height)
            };

            // Without child.
            control.SetDisplayRectLocation(scrollX, scrollY);
            Assert.Equal(new Rectangle(0, 0, width, height), control.DisplayRectangle);
            Assert.Equal(Point.Empty, control.AutoScrollPosition);

            // With child.
            var child = new LargeControl();

            control.Controls.Add(child);
            Assert.Equal(child.ExpectedSize, child.Bounds);

            control.SetDisplayRectLocation(scrollX, scrollY);
            Assert.Equal(expectedDisplayRectangleSize, control.DisplayRectangle.Size);
            Assert.Equal(expectedDisplayRectangleLocation, control.DisplayRectangle.Location);
            Assert.Equal(expectedDisplayRectangleLocation, control.AutoScrollPosition);
            Assert.Equal(child.ExpectedSize, child.Bounds);
        }
        public static IEnumerable <object[]> ScrollControlIntoView_TestData()
        {
            // Can't scroll - invalid child.
            yield return(new object[] { true, true, true, new Size(70, 80), null, new Rectangle(0, 0, 70, 80) });

            yield return(new object[] { false, true, true, new Size(70, 80), null, new Rectangle(0, 0, 70, 80) });

            yield return(new object[] { true, true, true, new Size(70, 80), new Control(), new Rectangle(0, 0, 70, 80) });

            // Can't scroll - not AutoScroll.
            yield return(new object[] { false, true, true, new Size(70, 80), new LargeControl(), new Rectangle(0, 0, 70, 80) });

            // Can't scroll - not HScroll or VScroll.
            yield return(new object[] { true, false, false, new Size(70, 80), new LargeControl(), new Rectangle(0, 0, 100, 150) });

            // Can't scroll - empty.
            yield return(new object[] { true, false, false, new Size(0, 80), new LargeControl(), new Rectangle(0, 0, 100, 150) });

            yield return(new object[] { true, false, false, new Size(-1, 80), new LargeControl(), new Rectangle(0, 0, 100, 150) });

            yield return(new object[] { true, false, false, new Size(70, 0), new LargeControl(), new Rectangle(0, 0, 100, 150) });

            yield return(new object[] { true, false, false, new Size(70, -1), new LargeControl(), new Rectangle(0, 0, 100, 150) });

            // Can scroll.
            yield return(new object[] { true, true, false, new Size(70, 80), new LargeControl(), new Rectangle(0, 0, 100, 150) });

            yield return(new object[] { true, false, true, new Size(70, 80), new LargeControl(), new Rectangle(0, 0, 100, 150) });

            yield return(new object[] { true, true, true, new Size(70, 80), new LargeControl(), new Rectangle(0, 0, 100, 150) });

            yield return(new object[] { true, true, false, new Size(70, 80), new SmallControl(), new Rectangle(0, 0, 70, 80) });

            yield return(new object[] { true, false, true, new Size(70, 80), new SmallControl(), new Rectangle(0, 0, 70, 80) });

            yield return(new object[] { true, true, true, new Size(70, 80), new SmallControl(), new Rectangle(0, 0, 70, 80) });

            foreach (bool hScroll in new bool[] { true, false })
            {
                var childControl  = new SmallControl();
                var parentControl = new LargeControl();
                parentControl.Controls.Add(childControl);
                yield return(new object[] { true, true, true, new Size(70, 80), parentControl, new Rectangle(0, 0, 100, 150) });

                yield return(new object[] { true, hScroll, true, new Size(70, 80), childControl, new Rectangle(0, 0, 100, 150) });
            }

            foreach (bool vScroll in new bool[] { true, false })
            {
                var childControl  = new SmallControl();
                var parentControl = new LargeControl();
                parentControl.Controls.Add(childControl);
                yield return(new object[] { true, true, true, new Size(70, 80), parentControl, new Rectangle(0, 0, 100, 150) });

                yield return(new object[] { true, true, vScroll, new Size(70, 80), childControl, new Rectangle(0, 0, 100, 150) });
            }
        }