主题:求“简化”移动窗体上控件的代码(跟+30)
各位高人:
我的问题是这样的:
如果窗口上有一个picture1控件,要实现按住鼠标拖动控件,有如下代码:
Dim mouseX As Integer
Dim mouseY As Integer
Dim moveX As Integer
Dim moveY As Integer
Dim down As Boolean
Private Sub Form_Load()
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
down = True
mouseX = X
mouseY = Y
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If down Then
moveX = Picture1.Left - mouseX + X
moveY = Picture1.Top - mouseY + Y
Picture1.Move moveX, moveY
End If
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
down = False
End Sub
可是现在,我的窗体上有20个picturebox,要套用上面的代码,需要做20次修改,太麻烦也太臃肿了!!不是编程人的风格![color=FF00FF]有没有利用“控件数组”简化代码的办法?[/color]
先谢谢了!!!
我的问题是这样的:
如果窗口上有一个picture1控件,要实现按住鼠标拖动控件,有如下代码:
Dim mouseX As Integer
Dim mouseY As Integer
Dim moveX As Integer
Dim moveY As Integer
Dim down As Boolean
Private Sub Form_Load()
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
down = True
mouseX = X
mouseY = Y
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If down Then
moveX = Picture1.Left - mouseX + X
moveY = Picture1.Top - mouseY + Y
Picture1.Move moveX, moveY
End If
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
down = False
End Sub
可是现在,我的窗体上有20个picturebox,要套用上面的代码,需要做20次修改,太麻烦也太臃肿了!!不是编程人的风格![color=FF00FF]有没有利用“控件数组”简化代码的办法?[/color]
先谢谢了!!!