PictureBox显示滚动条方法:
1.放置在Panl内,panl属性AutoScroll=True
2.PictureBox属性Dock为None,Anchor默认值,SizeMode为AutoSize
设置完毕,PictureBox就和Panl共用滚动条了。
通过鼠标滚轮滚动图片,Shift+中轴横向滚动
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load '注册窗体鼠标滚动事件 AddHandler Me.MouseWheel, AddressOf picImg_MouseWheel End Sub
Private Sub picImg_MouseWheel(ByVal sender As Object, ByVal e As MouseEventArgs) '获取光标位置 Dim p As Point = New Point(e.X, e.Y) '换算成相对本窗体的位置 p.Offset(Me.Location.X, Me.Location.Y) '判断是否在panel内 If (Me.Panel1.RectangleToScreen(Panel1.DisplayRectangle).Contains(p)) Then 'Shift+鼠标,横向滚动 If Control.ModifierKeys = Keys.Shift Then Panel1.AutoScrollPosition = New Point(Panel1.HorizontalScroll.Value - e.Delta, _ Panel1.VerticalScroll.Value) Else '竖向滚动 Panel1.AutoScrollPosition = New Point(Panel1.HorizontalScroll.Value, _ Panel1.VerticalScroll.Value - e.Delta) End If End If End Sub