該類型的操作沒有單一設置,因爲當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
爲什麼不呢?請解釋。 –