Exemplo n.º 1
0
        public void ScrollableControl_AutoScrollMinSize_Set_GetReturnsExpected(Size value)
        {
            var control = new ScrollableControl
            {
                AutoScrollMinSize = value
            };

            Assert.Equal(value, control.AutoScrollMinSize);
            Assert.Equal(value != Size.Empty, control.AutoScroll);

            // Set same.
            control.AutoScrollMinSize = value;
            Assert.Equal(value, control.AutoScrollMinSize);
            Assert.Equal(value != Size.Empty, control.AutoScroll);
        }
Exemplo n.º 2
0
	public ScrollingTest ()
	{
		paint_count_button = new Button ();
		paint_count_button.Text = "Print Paint Count (stdout)";
		paint_count_button.Dock = DockStyle.Bottom;
		paint_count_button.Click += new EventHandler (PrintPaintCount);
		
		scrollable = new ScrollableControl ();
		scrollable.Dock = DockStyle.Fill;
		scrollable.BackColor = Color.Red;
		scrollable.Paint += new PaintEventHandler (PaintArea);

		Controls.Add (paint_count_button);
		Controls.Add (scrollable);
	}
Exemplo n.º 3
0
        private void ScrollToPrice(decimal currentPrice, ScrollableControl panel)
        {
            var relativePrice = (double)(currentPrice - orderBookControl.PriceStart) /
                                (double)(orderBookControl.PriceEnd - orderBookControl.PriceStart);

            var scrollSize = panel.VerticalScroll.Maximum - panel.VerticalScroll.Minimum;

            var offset = panel.VerticalScroll.Minimum - panel_big.Height / 2;

            var verticalScrollValue = (int)(scrollSize * (1 - relativePrice) + offset);

            verticalScrollValue = Math.Max(panel.VerticalScroll.Minimum, Math.Min(panel.VerticalScroll.Maximum, verticalScrollValue));

            panel.VerticalScroll.Value = verticalScrollValue;
        }
Exemplo n.º 4
0
        public void AutoScroll()
        {
            ScrollableControl sc = new ScrollableControl();

            Assert.IsFalse(sc.AutoScroll, "#A1");
            Assert.AreEqual(0, sc.Controls.Count, "#A2");

            sc.AutoScroll = true;
            Assert.IsTrue(sc.AutoScroll, "#B1");
            Assert.AreEqual(0, sc.Controls.Count, "#B2");

            sc.AutoScroll = false;
            Assert.IsFalse(sc.AutoScroll, "#C1");
            Assert.AreEqual(0, sc.Controls.Count, "#C2");
        }
Exemplo n.º 5
0
    public ScrollingTest()
    {
        paint_count_button        = new Button();
        paint_count_button.Text   = "Print Paint Count (stdout)";
        paint_count_button.Dock   = DockStyle.Bottom;
        paint_count_button.Click += new EventHandler(PrintPaintCount);

        scrollable           = new ScrollableControl();
        scrollable.Dock      = DockStyle.Fill;
        scrollable.BackColor = Color.Red;
        scrollable.Paint    += new PaintEventHandler(PaintArea);

        Controls.Add(paint_count_button);
        Controls.Add(scrollable);
    }
Exemplo n.º 6
0
        public void DockPaddingEdges_Clone_InvokeWithOwner_ReturnsExpected()
        {
            var owner = new ScrollableControl
            {
                Padding = new Padding(1, 2, 3, 4)
            };
            ICloneable original = owner.DockPadding;

            ScrollableControl.DockPaddingEdges padding = (ScrollableControl.DockPaddingEdges)original.Clone();
            Assert.Equal(0, padding.All);
            Assert.Equal(1, padding.Left);
            Assert.Equal(2, padding.Top);
            Assert.Equal(3, padding.Right);
            Assert.Equal(4, padding.Bottom);
        }
        /// <summary>
        ///     Enables scrolling the given <paramref name="control"/> vertically with the
        ///     <kbd>Up</kbd>, <kbd>Down</kbd>, <kbd>Page Up</kbd>, and <kbd>Page Down</kbd> keys.
        /// </summary>
        /// <param name="control">
        ///     A scrollable control that requires keyboard support for vertical scrolling.
        /// </param>
        public static void EnableVerticalKeyboardScroll(this ScrollableControl control)
        {
            KeyEventHandler onKeyDown = (sender, args) => OnKeyDown(control, args);

            var form = control.FindForm();

            if (form == null)
            {
                control.KeyDown += onKeyDown;
                return;
            }

            form.KeyPreview = true;
            form.KeyDown   += onKeyDown;
        }
Exemplo n.º 8
0
    public bool Construct()
    {
        if (didConstruct != null)
        {
            return(false);
        }
        didConstruct = new Dictionary <string, string>();

        scrollableControl = new ScrollableControl();

        ConfigureWindow();
        ConstructInnerWindow();

        return(true);
    }
Exemplo n.º 9
0
        public void ScrollProperties_Minimum_Set_GetReturnsExpected(int value)
        {
            var control    = new ScrollableControl();
            var properties = new SubScrollProperties(control)
            {
                Value   = 5,
                Minimum = value
            };

            Assert.Equal(100, properties.Maximum);
            Assert.Equal(value, properties.Minimum);
            Assert.Equal(5, properties.Value);
            Assert.Equal(10, properties.LargeChange);
            Assert.Equal(1, properties.SmallChange);
        }
Exemplo n.º 10
0
        /// <summary>
        ///  Begins a drag operation.  A designer should examine the list of components
        ///  to see if it wants to support the drag.  If it does, it should return
        ///  true.  If it returns true, the designer should provide
        ///  UI feedback about the drag at this time.  Typically, this feedback consists
        ///  of an inverted rectangle for each component, or a caret if the component
        ///  is text.
        /// </summary>
        public virtual bool BeginDrag(object[] components, SelectionRules rules, int initialX, int initialY)
        {
            dragOffset     = new Rectangle();
            originalCoords = null;
            this.rules     = rules;

            dragControls = new Control[components.Length];
            for (int i = 0; i < components.Length; i++)
            {
                Debug.Assert(components[i] is IComponent, "Selection UI handler only deals with IComponents");
                dragControls[i] = GetControl((IComponent)components[i]);
                Debug.Assert(dragControls[i] != null, "Everyone must have a control");
            }

            // allow the cliprect to go just beyond the window by one grid.  This helps with round off
            // problems.  We can only do this if the container itself is not in the selection.  Also,
            // if the container is a form and it has autoscroll turned on, we allow a drag beyond the
            // container boundary on the width and height, but not top and left.
            //
            bool       containerSelected = false;
            IComponent container         = GetComponent();

            for (int i = 0; i < components.Length; i++)
            {
                if (components[i] == container)
                {
                    containerSelected = true;
                    break;
                }
            }

            if (!containerSelected)
            {
                Control   containerControl = GetControl();
                Size      snapSize         = GetCurrentSnapSize();
                Rectangle containerRect    = containerControl.RectangleToScreen(containerControl.ClientRectangle);
                containerRect.Inflate(snapSize.Width, snapSize.Height);
                ScrollableControl sc = GetControl() as ScrollableControl;
                if (sc != null && sc.AutoScroll)
                {
                    Rectangle screen = SystemInformation.VirtualScreen;
                    containerRect.Width  = screen.Width;
                    containerRect.Height = screen.Height;
                }
            }

            return(true);
        }
Exemplo n.º 11
0
 public bool CanExtend(object extendee)
 {
     if (extendee is ScrollableControl)
     {
         ScrollableControl control = (ScrollableControl)extendee;
         if (control.AutoScroll == true)
         {
             return(true);
         }
     }
     else if (extendee is TreeView)
     {
         TreeView control = (TreeView)extendee;
         if (control.Scrollable)
         {
             return(true);
         }
     }
     else if (extendee is TextBox)
     {
         TextBox control = (TextBox)extendee;
         if (control.Multiline && control.ScrollBars != ScrollBars.None)
         {
             return(true);
         }
     }
     else if (extendee is RichTextBox)
     {
         return(true);
     }
     else if (extendee is ListBox)
     {
         return(true);
     }
     else if (extendee is ComboBox)
     {
         return(true);
     }
     else if (extendee is ListView)
     {
         return(true);
     }
     else if (extendee is DataGridView)
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 12
0
        /// <summary>
        ///     attach this class to any dockable type of container control
        ///     to make it dockable.
        ///     Attach a container control and use it as a grip handle. The handle must support mouse move events.
        ///     Supply a splitter control to allow resizing of the docked container
        /// </summary>
        /// <param name="container">control to be dockable</param>
        /// <param name="handle">handle to be used to track the mouse movement (e.g. caption of the container)</param>
        /// <param name="splitter">splitter to resize the docked container (optional)</param>
        /// <exception cref="ArgumentException">container cannot be null</exception>
        public IFloaty Attach(ScrollableControl container, Control handle, Splitter splitter)
        {
            var dockState = new DockState
            {
                Container = container ?? throw new ArgumentException("container cannot be null"),
                                  Handle = handle ?? throw new ArgumentException("handle cannot be null"),
                                                 OrgDockHost = _dockHost,
                                                 Splitter    = splitter
            };

            var floaty = new Floaty(this);

            floaty.Attach(dockState);
            Floaties.Add(floaty);
            return(floaty);
        }
Exemplo n.º 13
0
        public void DockPaddingEdges_All_SetWithoutOwner_GetReturnsExpected(int value)
        {
            var owner = new ScrollableControl
            {
                Padding = new Padding(1, 2, 3, 4)
            };
            ICloneable original = owner.DockPadding;

            ScrollableControl.DockPaddingEdges padding = (ScrollableControl.DockPaddingEdges)original.Clone();
            padding.All = value;
            Assert.Equal(value, padding.All);
            Assert.Equal(value, padding.Left);
            Assert.Equal(value, padding.Top);
            Assert.Equal(value, padding.Right);
            Assert.Equal(value, padding.Bottom);
        }
Exemplo n.º 14
0
        public void TableLayoutPanel_GetControlFromPosition_ControlExistsAddedToContainer_ReturnsExpected(int columnSpan, int rowSpan, int column, int row)
        {
            var control = new ScrollableControl
            {
                Visible = true
            };
            var panel = new TableLayoutPanel();

            panel.Controls.Add(control);
            panel.SetColumnSpan(control, columnSpan);
            panel.SetRowSpan(control, rowSpan);
            panel.SetColumn(control, 10);
            panel.SetRow(control, 11);

            Assert.Equal(control, panel.GetControlFromPosition(column, row));
        }
Exemplo n.º 15
0
        public void TableLayoutPanel_GetPositionFromControl_ControlExists_ReturnsExpected(int columnSpan, int rowSpan)
        {
            var control = new ScrollableControl
            {
                Visible = true
            };
            var panel = new TableLayoutPanel();

            panel.Controls.Add(control);
            panel.SetColumn(control, 1);
            panel.SetRow(control, 2);
            panel.SetColumnSpan(control, columnSpan);
            panel.SetRowSpan(control, rowSpan);

            Assert.Equal(new TableLayoutPanelCellPosition(1, 2), panel.GetPositionFromControl(control));
        }
Exemplo n.º 16
0
        public void ScrollProperties_Minimum_SetGreaterThanValueAndMaximum_SetsValueAndMinimum()
        {
            var control    = new ScrollableControl();
            var properties = new SubScrollProperties(control)
            {
                Value   = 10,
                Maximum = 8,
                Minimum = 12
            };

            Assert.Equal(12, properties.Maximum);
            Assert.Equal(12, properties.Minimum);
            Assert.Equal(12, properties.Value);
            Assert.Equal(1, properties.LargeChange);
            Assert.Equal(1, properties.SmallChange);
        }
Exemplo n.º 17
0
 public void DockPaddingEdges_All_SetWithOwner_GetReturnsExpected(int value, int expectedValue, int expectedPaddingAll)
 {
     using var owner = new ScrollableControl();
     ScrollableControl.DockPaddingEdges padding = owner.DockPadding;
     padding.All = value;
     Assert.Equal(expectedValue, padding.All);
     Assert.Equal(expectedValue, padding.Left);
     Assert.Equal(expectedValue, padding.Top);
     Assert.Equal(expectedValue, padding.Right);
     Assert.Equal(expectedValue, padding.Bottom);
     Assert.Equal(expectedPaddingAll, owner.Padding.All);
     Assert.Equal(expectedValue, owner.Padding.Left);
     Assert.Equal(expectedValue, owner.Padding.Top);
     Assert.Equal(expectedValue, owner.Padding.Right);
     Assert.Equal(expectedValue, owner.Padding.Bottom);
 }
        public void ScrollProperties_Maximum_SetLessThanValueAndMinimum_SetsValueAndMinimum()
        {
            var container  = new ScrollableControl();
            var properties = new SubScrollProperties(container)
            {
                Value   = 10,
                Minimum = 8,
                Maximum = 5
            };

            Assert.Equal(5, properties.Maximum);
            Assert.Equal(5, properties.Minimum);
            Assert.Equal(5, properties.Value);
            Assert.Equal(1, properties.LargeChange);
            Assert.Equal(1, properties.SmallChange);
        }
Exemplo n.º 19
0
        public void TableLayoutPanel_GetControlFromPosition_OutOfRange_ReturnsNull(int columnSpan, int rowSpan, int column, int row)
        {
            var control = new ScrollableControl
            {
                Visible = true
            };
            var panel = new TableLayoutPanel();

            panel.Controls.Add(control);
            panel.SetColumnSpan(control, columnSpan);
            panel.SetRowSpan(control, rowSpan);
            panel.SetColumn(control, 10);
            panel.SetRow(control, 11);

            Assert.Null(panel.GetControlFromPosition(column, row));
        }
        public static void RefreshControl(Control c)
        {
            ScrollableControl sc = c as ScrollableControl;

            if (sc != null)
            {
                sc.Refresh();
            }
            else
            {
                if (c != null)
                {
                    c.Refresh();
                }
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Sets a value which determines if Pan and Flick gestures are automatically handled in the ScrollableControl.
        /// </summary>
        /// <param name="control">The ScrollableControl</param>
        /// <param name="value">true to enable automatic gestures, false to disable.</param>
        /// <remarks>
        /// <list type="table"><listheader><term>Requirements</term><description></description></listheader>
        /// <item><term>Windows Mobile</term><description>Windows Mobile 6.1 and later</description></item>
        /// <item><term>Windows Embedded</term><description>Windows Embedded 6.0</description></item>
        /// </list>
        /// </remarks>
        public static void SetGesturesEnabled(this ScrollableControl control, bool value)
        {
            if ((SystemSettingsInTheHand.Platform != WinCEPlatform.Smartphone) && InTheHand.NativeMethods.IsMobile6 && System.Environment.OSVersion.Version.Major < 7)
            {
                try
                {
                    WAGINFO wi = new WAGINFO();
                    wi.cbSize  = Marshal.SizeOf(wi);
                    wi.dwFlags = (value ? WAGIF.VSCROLLABLE | WAGIF.HSCROLLABLE : 0) | WAGIF.OWNERANIMATE;

                    bool success = NativeMethods.SetWindowAutoGesture(control.Handle, ref wi);
                }
                catch
                {
                }
            }
        }
Exemplo n.º 22
0
        public void ScrollProperties_Value_SetAutoScrollContainer_GetReturnsExpected(int value)
        {
            var control = new ScrollableControl
            {
                AutoScroll = true
            };
            var properties = new SubScrollProperties(control)
            {
                Value = value
            };

            Assert.Equal(100, properties.Maximum);
            Assert.Equal(0, properties.Minimum);
            Assert.Equal(value, properties.Value);
            Assert.Equal(10, properties.LargeChange);
            Assert.Equal(1, properties.SmallChange);
        }
Exemplo n.º 23
0
        public void ScrollProperties_Minimum_SetAutoScrollContainer_Nop(int value)
        {
            var control = new ScrollableControl
            {
                AutoScroll = true
            };
            var properties = new SubScrollProperties(control)
            {
                Minimum = value
            };

            Assert.Equal(100, properties.Maximum);
            Assert.Equal(0, properties.Minimum);
            Assert.Equal(0, properties.Value);
            Assert.Equal(10, properties.LargeChange);
            Assert.Equal(1, properties.SmallChange);
        }
Exemplo n.º 24
0
        public void ScrollableControl_ScaleControl_InvokeWithDockPadding_Success()
        {
            var control = new ScrollableControl();

            control.Padding = new Padding(1, 2, 3, 4);
            Assert.Equal(1, control.DockPadding.Left);
            Assert.Equal(2, control.DockPadding.Top);
            Assert.Equal(3, control.DockPadding.Right);
            Assert.Equal(4, control.DockPadding.Bottom);
            control.Scale(new SizeF(10, 20));

            Assert.Equal(10, control.DockPadding.Left);
            Assert.Equal(40, control.DockPadding.Top);
            Assert.Equal(30, control.DockPadding.Right);
            Assert.Equal(80, control.DockPadding.Bottom);
            Assert.Equal(new Padding(10, 40, 30, 80), control.Padding);
        }
        public void ScrollProperties_SmallChange_SetAutoScrollContainer_GetReturnsExpected(int value, int expectedValue)
        {
            var container = new ScrollableControl
            {
                AutoScroll = true
            };
            var properties = new SubScrollProperties(container)
            {
                SmallChange = value
            };

            Assert.Equal(expectedValue, properties.SmallChange);

            // Set same.
            properties.SmallChange = value;
            Assert.Equal(expectedValue, properties.SmallChange);
        }
Exemplo n.º 26
0
        private void logTextBox_MouseWheel(object sender, MouseEventArgs e)
        {
            if (Math.Abs(e.Delta) < 120)
            {
                return;
            }

            ScrollableControl control = (ScrollableControl)this;
            var scroll = control.VerticalScroll;

            var maximum = 1 + scroll.Maximum - scroll.LargeChange;
            var delta   = -(e.Delta / 120) * scroll.SmallChange;
            var offset  = Math.Min(Math.Max(scroll.Value + delta, scroll.Minimum), maximum);

            scroll.Value = offset;
            scroll.Value = offset;
        }
Exemplo n.º 27
0
        public void ScrollProperties_LargeChange_SetAutoScrollContainer_GetReturnsExpected(int value)
        {
            using var container = new ScrollableControl
                  {
                      AutoScroll = true
                  };
            var properties = new SubScrollProperties(container)
            {
                LargeChange = value
            };

            Assert.Equal(value, properties.LargeChange);

            // Set same.
            properties.LargeChange = value;
            Assert.Equal(value, properties.LargeChange);
        }
Exemplo n.º 28
0
        public static Bitmap ScrollableControlToBitmap(ScrollableControl canvas, bool fullSize, bool includeHidden)
        {
            canvas.AutoScrollPosition = new Point(0, 0);
            if (includeHidden)
            {
                canvas.SuspendLayout();
                foreach (Control child in canvas.Controls)
                {
                    child.Visible = true;
                }
                canvas.ResumeLayout(true);
            }

            canvas.PerformLayout();
            Size containerSize = canvas.DisplayRectangle.Size;

            if (fullSize)
            {
                containerSize.Width  = Math.Max(containerSize.Width, canvas.ClientSize.Width);
                containerSize.Height = Math.Max(containerSize.Height, canvas.ClientSize.Height);
            }
            else
            {
                containerSize = (canvas is Form) ? canvas.PreferredSize : canvas.ClientSize;
            }

            var bitmap = new Bitmap(containerSize.Width, containerSize.Height, PixelFormat.Format32bppArgb);

            bitmap.SetResolution(canvas.DeviceDpi, canvas.DeviceDpi);

            var graphics = Graphics.FromImage(bitmap);

            graphics.Clear(canvas.BackColor);
            var rtfPrinter = new RichEditPrinter(graphics);

            try
            {
                DrawNestedControls(canvas, canvas, new Rectangle(Point.Empty, containerSize), bitmap, rtfPrinter);
                return(bitmap);
            }
            finally
            {
                rtfPrinter.Dispose();
                graphics.Dispose();
            }
        }
        public void TableLayoutSettingsTypeConverter_ConvertTo_HasControlChildren_ReturnsExpected()
        {
            var panel   = new TableLayoutPanel();
            var control = new ScrollableControl();
            TableLayoutSettings settings = Assert.IsType <TableLayoutSettings>(panel.LayoutSettings);

            panel.Controls.Add(control);
            settings.SetColumnSpan(control, 1);
            settings.SetRowSpan(control, 2);
            settings.SetColumn(control, 3);
            settings.SetRow(control, 4);

            var    converter = new TableLayoutSettingsTypeConverter();
            string result    = Assert.IsType <string>(converter.ConvertTo(settings, typeof(string)));

            Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-16""?><TableLayoutSettings><Controls><Control Name="""" Row=""4"" RowSpan=""2"" Column=""3"" ColumnSpan=""1"" /></Controls><Columns Styles="""" /><Rows Styles="""" /></TableLayoutSettings>", result);
        }
Exemplo n.º 30
0
        public void ScrollableControl_Visible_Set_GetReturnsExpected(bool value)
        {
            var control = new ScrollableControl
            {
                Visible = value
            };

            Assert.Equal(value, control.Visible);

            // Set same.
            control.Visible = value;
            Assert.Equal(value, control.Visible);

            // Set different.
            control.Visible = !value;
            Assert.Equal(!value, control.Visible);
        }
Exemplo n.º 31
0
        public void ScrollableControl_Visible_Set_GetReturnsExpected()
        {
            var control = new ScrollableControl
            {
                Visible = false
            };

            Assert.False(control.Visible);

            // Set same.
            control.Visible = false;
            Assert.False(control.Visible);

            // Set different.
            control.Visible = true;
            Assert.True(control.Visible);
        }
		public VScrollProperties (ScrollableControl container) : base (container)
		{
			scroll_bar = container.vscrollbar;
		}
 // Constructors
 public VScrollProperties(ScrollableControl container)
 {
 }