SetScrollInfo on PrintPreviewControl

Answered SetScrollInfo on PrintPreviewControl

  • 2009年7月28日 22:49
     
     
    I am working with a PrintPreviewControl. When it is zoomed in so that only a portion of the current page is shown scrollbars appear to allow the user to scroll over the entire page. I want to allow the user to scroll the image by clicking and dragging. I'm trying to use GetScrollInfo and SetScrollInfo but for some reason only one scroll bar is updated.

    I am using Visual Studio 2005 on Vista.

    Here is some sample code:

            Point dragOffset;
            private void printPreviewControl1_MouseDown(object sender, MouseEventArgs e) {
                dragOffset = e.Location;
            }

            private void printPreviewControl1_MouseMove(object sender, MouseEventArgs e) {
                if (e.Button == MouseButtons.Left) {
                    scroll(e.X - dragOffset.X, e.Y - dragOffset.Y);
                    dragOffset = e.Location;
                    printPreviewControl1.Invalidate();
                    printPreviewControl1.Refresh();
                }
            }

            private void scroll(int dx, int dy) {
                SCROLLINFO info = new SCROLLINFO();
                info.Size = Marshal.SizeOf(info);
                info.Mask = 0xff;

                GetScrollInfo(printPreviewControl1.Handle, SB_HORZ, ref info);
                info.Pos -= dx;
                SetScrollInfo(printPreviewControl1.Handle, SB_HORZ, ref info, true);
                PostMessageA((IntPtr)printPreviewControl1.Handle, WM_HSCROLL, SB_THUMBPOSITION + 0x10000 * info.Pos, 0);
               
                GetScrollInfo(printPreviewControl1.Handle, SB_VERT, ref info);
                info.Pos -= dy;
                SetScrollInfo(printPreviewControl1.Handle, SB_VERT, ref info, true);
                PostMessageA((IntPtr)printPreviewControl1.Handle, WM_VSCROLL, SB_THUMBPOSITION + 0x10000 * info.Pos, 0);
            }

全部回复