I am trying to create a custom print preview dialog in VB.Net which allows for utilization of the mouse wheel. I am experiencing some really odd behavior. There are three main goals I want to accomplish with the mouse wheel. I have achieved goal 1 and 3, but have not been able to accomplish goal 2. Firstly, if the user held down the control key and spun the mouse wheel I wanted to zoom in and out respectively. That works fine. Secondly, I wanted, when appropriate to be able to scroll up and down to fully view each page in the preview. Thirdly I wanted to be able to scroll onto other pages of the document using the mouse wheel. This also works fine. Here is my Code:
Public Class CustomPrintPreview : Inherits PrintPreviewDialog
Public Sub New()
AddHandler Me.MouseWheel, AddressOf mousewheel_scroll
End Sub
Private Sub mousewheel_scroll(ByVal sender As Object, e As System.Windows.Forms.MouseEventArgs)
If e.Delta > 0 Then
If My.Computer.Keyboard.CtrlKeyDown Then
Me.PrintPreviewControl.Zoom = Math.Min(Me.PrintPreviewControl.Zoom + 0.25, 5)
ElseIf Me.AutoScrollPosition.Y > 0 Then '''''''''''trouble spot!!!!!
Me.AutoScrollPosition = New Point(Me.AutoScrollPosition.X, Math.Max(0, Me.AutoScrollPosition.Y - 20))
Else
Me.PrintPreviewControl.StartPage = Math.Max(Me.PrintPreviewControl.StartPage - 1, 0)
End If
Else
If My.Computer.Keyboard.CtrlKeyDown Then
Me.PrintPreviewControl.Zoom = Math.Max(Me.PrintPreviewControl.Zoom - 0.25, 0.25)
ElseIf Me.AutoScrollPosition.Y < 1000 Then ''''''''''trouble spot!!!!
Me.AutoScrollPosition = New Point(Me.AutoScrollPosition.X, Math.Min(1000, Me.AutoScrollPosition.Y + 20))
Else
Me.PrintPreviewControl.StartPage = Math.Min(Me.PrintPreviewControl.StartPage + 1, endpage)
End If
End If
End Sub
End Class
I have tried a number of options at the places I marked trouble spots such as:
Me.VerticalScroll.Value = Me.VerticalScroll.Value + 20
Me.VerticalScroll.Visible = True
Me.AutoScroll = True
Me.VScroll = True
Me.PrintPreviewControl.autoscroll
Me.PrintPreviewControl.verticalscroll.visible
Me.PrintPreviewControl.verticalscroll.value
Here is the weird behavior. When I run this code I get a print preview dialog. As soon as I zoom in a vertical scroll bar appears(like I want it to). But I cannot access it. It is not accessible through me.autoscroll. I can use the debugger to disable me.autoscroll, to modify me.verticalscroll, but it has no effect on the actual scroll bar that I see displayed. I can use the scroll bar that is displayed to physically scroll the document. But no matter what I do, me.verticalscroll.value remains at 0. me.autoscrollposition remains at (0,0). An auto scroll is instantiating, but it is not accessible through me.autoscroll. I have also used the debugger to search through me.controls, me.form, me.activecontrol, me.activeform. I cannot access the autoscroll from the print preview dialog programmatically. Can you please help me? Thank you. I recognize I have a few things to work out still once I am able to access the autoscroll.