Public Partial Class ImageViewer_ExternalScrollBars
Inherits System.Windows.Forms.Form
#Region "Constructors"
Public Sub New()
InitializeComponent()
' ...
AddHandler imageViewer.ZoomChanged, New System.EventHandler(Of Vintasoft.Imaging.UI.ZoomChangedEventArgs)(AddressOf imageViewer_ZoomChanged)
AddHandler imageViewer.ImageLoaded, New System.EventHandler(Of Vintasoft.Imaging.ImageLoadedEventArgs)(AddressOf imageViewer_ImageLoaded)
AddHandler imageViewer.SizeChanged, New System.EventHandler(AddressOf imageViewer_SizeChanged)
AddHandler hScrollBar1.ValueChanged, New System.EventHandler(AddressOf ScrollBar_ValueChanged)
AddHandler vScrollBar1.ValueChanged, New System.EventHandler(AddressOf ScrollBar_ValueChanged)
' ...
imageViewer.AutoScroll = False
End Sub
#End Region
#Region "Methods"
''' <summary>
''' Image viewer size is changed.
''' </summary>
Private Sub imageViewer_SizeChanged(sender As Object, e As System.EventArgs)
SetScrollBarParams()
End Sub
''' <summary>
''' Image is loaded in image viewer.
''' </summary>
Private Sub imageViewer_ImageLoaded(sender As Object, e As Vintasoft.Imaging.ImageLoadedEventArgs)
SetScrollBarParams()
End Sub
''' <summary>
''' Image viewer zoom is changed.
''' </summary>
Private Sub imageViewer_ZoomChanged(sender As Object, e As Vintasoft.Imaging.UI.ZoomChangedEventArgs)
SetScrollBarParams()
End Sub
''' <summary>
''' Sets parameters of scroll bars.
''' </summary>
Private Sub SetScrollBarParams()
' initialize horizontal scroll bar
Dim width As Integer = imageViewer.ViewerState.AutoScrollSize.Width
hScrollBar1.Minimum = 0
hScrollBar1.Maximum = width + width \ 5
hScrollBar1.LargeChange = width \ 5
hScrollBar1.SmallChange = width \ 20
hScrollBar1.Enabled = width <> 0
' initialize vertical scroll bar
Dim height As Integer = imageViewer.ViewerState.AutoScrollSize.Height
vScrollBar1.Minimum = 0
vScrollBar1.Maximum = height + height \ 5
vScrollBar1.LargeChange = height \ 5
vScrollBar1.SmallChange = height \ 20
vScrollBar1.Enabled = height <> 0
End Sub
''' <summary>
''' Scrollbar value is changed.
''' </summary>
Private Sub ScrollBar_ValueChanged(sender As Object, e As System.EventArgs)
Dim currentPosition As New System.Drawing.PointF(CSng(hScrollBar1.Value), CSng(vScrollBar1.Value))
imageViewer.ViewerState.AutoScrollPosition = currentPosition
End Sub
#End Region
End Class