2012年5月11日 星期五
如何讓panel中的捲軸能夠用滑鼠滾輪控制
如下所示,該怎麼讓滑鼠中間滾輪能捲動畫面?謝謝大大。
Public Class Form1
Dim obj() As PictureBox
Dim objlabel() As Label
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ReDim obj(23)
ReDim objlabel(23)
Panel1.AutoScroll = True
For i As Integer = 0 To 3
For j As Integer = 0 To 5
Dim n As Integer = i * 6 + j
obj(n) = New PictureBox
obj(n).Location = New Point(20 + i * 152, 20 + j * 130)
obj(n).BorderStyle = BorderStyle.Fixed3D
obj(n).Size = New Size(132, 100)
objlabel(n) = New Label
objlabel(n).Text = "Label" & CStr(n)
objlabel(n).Location = New Point(20 + i * 152, 120 + j * 130)
objlabel(n).TextAlign = ContentAlignment.MiddleCenter
objlabel(n).BorderStyle = BorderStyle.FixedSingle
objlabel(n).Size = New Size(132, 20)
Panel1.Controls.Add(obj(n))
Panel1.Controls.Add(objlabel(n))
Next
Next
End Sub
End Class
Answer:
測試看看在Form的MouseWheel事件中加入以下程式碼看看能否達到您的需求,目前測試看起來panel收不到MouseWheel事件,詳細部分要再找資料看看
Private Sub Form1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel
Panel1.AutoScrollPosition = New Point(0, Panel1.VerticalScroll.Value + Not e.Delta)
End Sub
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言