public PrintPreviewControl()
        {
            autozoom  = true;
            columns   = 1;
            rows      = 0;
            startPage = 0;

            this.BackColor = SystemColors.AppWorkspace;

            controller = new PreviewPrintController();

            vbar = new ImplicitVScrollBar();
            hbar = new ImplicitHScrollBar();

            vbar.Visible       = false;
            hbar.Visible       = false;
            vbar.ValueChanged += new EventHandler(VScrollBarValueChanged);
            hbar.ValueChanged += new EventHandler(HScrollBarValueChanged);

            SuspendLayout();
            Controls.AddImplicit(vbar);
            Controls.AddImplicit(hbar);
            ResumeLayout();
        }
예제 #2
0
        internal void SizeScrollBars()
        {
            if (lock_sizing)
            {
                return;
            }

            if (!IsHandleCreated)
            {
                return;
            }

            if (Controls.Count == 0 || ((Form)Controls [0]).WindowState == FormWindowState.Maximized)
            {
                if (hbar != null)
                {
                    hbar.Visible = false;
                }
                if (vbar != null)
                {
                    vbar.Visible = false;
                }
                if (sizegrip != null)
                {
                    sizegrip.Visible = false;
                }
                return;
            }

            int right  = 0;
            int left   = 0;
            int top    = 0;
            int bottom = 0;

            foreach (Form child in Controls)
            {
                if (!child.Visible)
                {
                    continue;
                }
                if (child.Right > right)
                {
                    right = child.Right;
                }
                if (child.Left < left)
                {
                    left = child.Left;
                }

                if (child.Bottom > bottom)
                {
                    bottom = child.Bottom;
                }
                if (child.Top < 0)
                {
                    top = child.Top;
                }
            }

            int available_width  = ClientSize.Width;
            int available_height = ClientSize.Height;

            bool need_hbar = false;
            bool need_vbar = false;

            if (right - left > available_width || left < 0)
            {
                need_hbar         = true;
                available_height -= SystemInformation.HorizontalScrollBarHeight;
            }
            if (bottom - top > available_height || top < 0)
            {
                need_vbar        = true;
                available_width -= SystemInformation.VerticalScrollBarWidth;

                if (!need_hbar && (right - left > available_width || left < 0))
                {
                    need_hbar         = true;
                    available_height -= SystemInformation.HorizontalScrollBarHeight;
                }
            }

            if (need_hbar)
            {
                if (hbar == null)
                {
                    hbar = new ImplicitHScrollBar();
                    Controls.AddImplicit(hbar);
                }
                hbar.Visible = true;
                CalcHBar(left, right, need_vbar);
            }
            else if (hbar != null)
            {
                hbar.Visible = false;
            }

            if (need_vbar)
            {
                if (vbar == null)
                {
                    vbar = new ImplicitVScrollBar();
                    Controls.AddImplicit(vbar);
                }
                vbar.Visible = true;
                CalcVBar(top, bottom, need_hbar);
            }
            else if (vbar != null)
            {
                vbar.Visible = false;
            }

            if (need_hbar && need_vbar)
            {
                if (sizegrip == null)
                {
                    sizegrip = new SizeGrip(this.ParentForm);
                    Controls.AddImplicit(sizegrip);
                }
                sizegrip.Location = new Point(hbar.Right, vbar.Bottom);
                sizegrip.Visible  = true;
                XplatUI.SetZOrder(sizegrip.Handle, vbar.Handle, false, false);
            }
            else if (sizegrip != null)
            {
                sizegrip.Visible = false;
            }

            XplatUI.InvalidateNC(Handle);
        }