我正试图在面板中移动图片框。如何使用vb.net在面板中移动图片框
这是我的代码:
Private dragging As Boolean
Private beginX, beginY As Integer
Private Sub Control_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
dragging = True
beginX = CType(sender, PictureBox).Location.X
beginY = CType(sender, PictureBox).Location.Y
End Sub
Private Sub Control_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dim cntrl As Control = CType(sender, Control)
If dragging = True Then
cntrl.Location = New Point(cntrl.Location.X + e.X - beginX, cntrl.Location.Y + e.Y - beginY)
'Me.Refresh()
End If
End Sub
Private Sub Control_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
dragging = False
End Sub
我想不通为什么这不工作。
我在循环 for循环 BTN =新的PictureBox 的AddHandler btn.MouseUp,AddressOf Control_MouseUp AddHandler的BTN创建图片框。 MouseDown,AddressOf Control_MouseDown AddHandler btn.MouseMove,AddressOf Control_MouseMove pnlLocker.Controls.Add(btn) 下一个 – ram
您应该编辑您的问题以包含该代码。 –
每当我点击图片框它闪烁,当我移动鼠标的图片框不会改变它的位置... – ram