这种类型的操作没有单一设置,因为当 PictureBox 尺寸小于 Panel 的客户空间时,您希望 PictureBox 居中,但当 PictureBox 尺寸超过 Panel 客户空间的大小时,您希望位置在零点并让滚动条处理视图。
尝试处理面板的调整大小事件,并在调整图片框大小时调用该事件:
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