【求救】用VB怎么做出鼠标拖动图片?
如题,我想在程序上用鼠标随意拖动图片,请问如何做?(我是一个新手,请各位大虾回答时尽量详细,100分送上,谢谢!)就是像拖动图片那样的普通拖动,鼠标单击并且移动,图片随鼠...
如题,我想在程序上用鼠标随意拖动图片,请问如何做?
(我是一个新手,请各位大虾回答时尽量详细,100分送上,谢谢!)
就是像拖动图片那样的普通拖动,鼠标单击并且移动,图片随鼠标移动;放开鼠标,图片停止移动。 展开
(我是一个新手,请各位大虾回答时尽量详细,100分送上,谢谢!)
就是像拖动图片那样的普通拖动,鼠标单击并且移动,图片随鼠标移动;放开鼠标,图片停止移动。 展开
展开全部
我按照你的要求制作了源程序例子,请下载:http://www.fileurls.com/download.ashx?id=smagxq
展开全部
在窗体上添加一个imagebox,加上图片
Option Explicit
Dim xx As Single, yy As Single
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
xx = X: yy = Y
End Sub
Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Image1.Move Image1.Left + X - xx, Image1.Top + Y - yy
End Sub
就这样
Option Explicit
Dim xx As Single, yy As Single
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
xx = X: yy = Y
End Sub
Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Image1.Move Image1.Left + X - xx, Image1.Top + Y - yy
End Sub
就这样
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Button = 1
xp = x
yp = y
Image1.MousePointer = 7
End Sub
Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If xp <> 0 And yp <> 0 Then
Image1.Left = Image1.Left + (x - xp)
Image1.Top = Image1.Top + (y - yp)
End If
xz = Image1.Left
yz = Image1.Top
End Sub
Private Sub Image1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Button = 1
xp = yp = 0
Image1.MousePointer = 0
End Sub
这个是拖拽部分的源码
不知道你具体需要什么 因为拖拽过程中还存在一些细节问题 比如:
图片是否放大缩小?
是否需要锁定拖拽范围?
Button = 1
xp = x
yp = y
Image1.MousePointer = 7
End Sub
Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If xp <> 0 And yp <> 0 Then
Image1.Left = Image1.Left + (x - xp)
Image1.Top = Image1.Top + (y - yp)
End If
xz = Image1.Left
yz = Image1.Top
End Sub
Private Sub Image1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Button = 1
xp = yp = 0
Image1.MousePointer = 0
End Sub
这个是拖拽部分的源码
不知道你具体需要什么 因为拖拽过程中还存在一些细节问题 比如:
图片是否放大缩小?
是否需要锁定拖拽范围?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
以下是相关的代码,VB6.0
Private DX As Single, DY As Single, PX As Single, PY As Single '鼠标拖拽效果用的变量
Private NowDrow As Long
'鼠标拖拽效果
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
PX = X: PY = Y
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Me.Cls
If NowDrow = 1 Then
Me.PaintPicture oLab, DX + X - PX, DY + Y - PY
Else
Me.PaintPicture oPic, DX + X - PX, DY + Y - PY
End If
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
DX = DX + X - PX: DY = DY + Y - PY
End Sub
Private DX As Single, DY As Single, PX As Single, PY As Single '鼠标拖拽效果用的变量
Private NowDrow As Long
'鼠标拖拽效果
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
PX = X: PY = Y
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Me.Cls
If NowDrow = 1 Then
Me.PaintPicture oLab, DX + X - PX, DY + Y - PY
Else
Me.PaintPicture oPic, DX + X - PX, DY + Y - PY
End If
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
DX = DX + X - PX: DY = DY + Y - PY
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
说详细点
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询