该类型的操作没有单一设置,因为当PictureBox尺寸小于Panel的客户端空间时,您希望PictureBox居中,但当PictureBox尺寸超出Panel的客户端尺寸时空间,你想要位置在零点,并让滚动条处理视图。
尝试操作面板上的调整大小事件,并调用事件当调整图片框:?在.NET滚动图片框]
Private Sub TrackBar1_Scroll(sender As Object, e As EventArgs) Handles TrackBar1.Scroll
PictureBox1.Size = New Size(64 * TrackBar1.Value, 64 * TrackBar1.Value)
Panel1.AutoScrollMinSize = PictureBox1.Size
Panel1_Resize(Panel1, EventArgs.Empty)
End Sub
Private Sub Panel1_Resize(sender As Object, e As EventArgs) Handles Panel1.Resize
If PictureBox1.Width > Panel1.ClientSize.Width Then
PictureBox1.Left = Panel1.AutoScrollPosition.X
Else
PictureBox1.Left = Panel1.ClientSize.Width/2 - PictureBox1.Width/2
End If
If PictureBox1.Height > Panel1.ClientSize.Height Then
PictureBox1.Top = Panel1.AutoScrollPosition.Y
Else
PictureBox1.Top = Panel1.ClientSize.Height/2 - PictureBox1.Height/2
End If
End Sub
的可能重复(http://stackoverflow.com/questions/3396973/scrolling-picturebox-in-net) –
我试过这个解决方案。它不适合我。 – user1208402
为什么不呢?请解释。 –