public void DockPaddingScroll()
        {
            ScrollableControl scrollable = new ScrollableControl();

            scrollable.Padding    = new Padding(10);
            scrollable.Size       = new Size(50, 50);
            scrollable.AutoScroll = true;

            Control c = new Control();

            c.Size   = scrollable.Size;           // Same size as parent, shouldn' need scrollbars
            c.Parent = scrollable;

            Form f = new Form();

            f.Controls.Add(scrollable);

            f.Show();

            Assert.AreEqual(false, scrollable.VerticalScroll.Visible, "#A0");

            ScrollableControl.DockPaddingEdges dock_padding = scrollable.DockPadding;
            Assert.IsTrue(dock_padding != null, "#B0");

            // Refresh the layout, now that is affected by the creation of DockPadding
            scrollable.PerformLayout();

            Assert.AreEqual(true, scrollable.VerticalScroll.Visible, "#C0");
        }
Example #2
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();
            }
        }
Example #3
0
        /// <summary>
        /// Disable all default scroll bar event handlers on any child controls of controlOverride.
        /// All mouse scrolls will cause the scroll bar on showScrollOn to change.
        /// </summary>
        public static void OverrideScrollBar(ScrollableControl showScrollOn,
                                             Control controlOverride)
        {
            controlOverride.Controls.Cast <Control>().ForEach(
                i => OverrideScrollBar(showScrollOn, i));

            controlOverride.MouseWheel += (s, e) =>
            {
                ((HandledMouseEventArgs)e).Handled = true;
                var scroll = showScrollOn.VerticalScroll;
                if (scroll.Visible)
                {
                    scroll.Value = Numbers.LimitToRange(scroll.Value - e.Delta,
                                                        scroll.Minimum, scroll.Maximum);
                    showScrollOn.PerformLayout();
                }
            };
        }