这都是最基础的技巧了,参照下述代码即可:
Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static ox As Integer, oy As Integer
If Button = 1 Then
Me.Left = Me.Left + X - ox
Me.Top = Me.Top + Y - oy
Else
ox = X
oy = Y
End If
End Sub
二楼 xzlxzlxzl 的回答应该说基本正确,但我认为应该是窗体的MouseMove事件。
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static ox As Integer, oy As Integer
If Button = 1 Then
Me.Left = Me.Left + X - ox
Me.Top = Me.Top + Y - oy
Else
ox = X
oy = Y
End If
End Sub
哦,题主问了两个问题,看成按住image了,没仔细审题。
第二问参照下述代码:
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Image1.Picture = LoadPicture("图片文件位置") '可以换成用LoadResPicture函数加载资源文件内容
End Sub
Private Sub Image1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Image1.Picture = LoadPicture("") '""里可以换成原图片文件路径,空字符串是取消inage控件里图片
End Sub