VB鼠标如何拖动文件?

xujundelaopo 2009-05-09 12:12:46
我希望做一个拖动的小软件,拖动“从站”进SHAPE1后,“从站1”自动加载到SHAPE1的中心位置,原“从站1”消失,“从站”回到原位置不变,重复操作,拖动“从站”进SHAPE2后,“从站2”自动加载到SHAPE2的中心位置,“从站”回到原位置不变,拖动“从站”进SHAPE3后,“从站3”自动加载到SHAPE3的中心位置,“从站”回到原位置不变,并且当“从站1”,“从站2”,“从站3”拖进对应的SHAPE框后可以拖出来,回到原来的位置。麻烦各位帮我看看。
...全文
94 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xujundelaopo 2009-05-09
  • 打赏
  • 举报
回复
Dim w1%, w2%, h1%, h2%, m%, k%, l%
Private Sub Form_Load()
k = Picture99(0).Left
l = Picture99(0).Top
End Sub


Private Sub Picture99_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Index = 0 Then
w1 = X - Picture99(0).Left: w2 = Picture99(0).Left + Picture99(0).Width - X
h1 = Y - Picture99(0).Top: h2 = Picture99(0).Top + Picture99(0).Height - Y
Else

End If

End Sub


Private Sub Picture99_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Index = 0 Then
m = m + 1
If (X - w1 > Shape1.Left And X + w2 < Shape1.Left + Shape1.Width _
And Y - h1 > Shape1.Top And Y + h2 < Shape1.Top + Shape1.Height) Then
Load Picture1(m)
Picture1(m).Left = Shape1.Left + Shape1.Width / 2 - Picture1(m).Width / 2: Picture1(m).Top = Shape1.Top + Shape1.Height / 2 - Picture1(m).Height / 2

ElseIf (X - w1 > Shape2.Left And X + w2 < Shape2.Left + Shape2.Width _
And Y - h1 > Shape2.Top And Y + h2 < Shape2.Top + Shape2.Height) Then
Load Picture2(m)
Picture1(m).Left = Shape2.Left + Shape2.Width / 2 - Picture1(m).Width / 2: Picture1(m).Top = Shape2.Top + Shape2.Height / 2 - Picture1(m).Height / 2

ElseIf (X - w1 > Shape3.Left And X + w2 < Shape3.Left + Shape3.Width _
And Y - h1 > Shape3.Top And Y + h2 < Shape3.Top + Shape3.Height) Then
Load Picture3(m)
Picture1(m).Left = Shape3.Left + Shape3.Width / 2 - Picture1(m).Width / 2: Picture1(m).Top = Shape3.Top + Shape3.Height / 2 - Picture1(m).Height / 2

End If
Picture1(m).Visible = True

If Index > 0 Then
If (X - w1 > Shape1.Left + Shape1.Width Or X + w2 < Shape1.Left _
Or Y - h1 > Shape1.Top + Shape1.Height Or Y + h2 < Shape1.Top) Then
Unload Picture1(Index)

ElseIf (X - w1 > Shape2.Left + Shape2.Width Or X + w2 < Shape2.Left _
Or Y - h1 > Shape2.Top + Shape2.Height Or Y + h2 < Shape2.Top) Then
Unload Picture2(Index)

ElseIf (X - w1 > Shape3.Left + Shape3.Width Or X + w2 < Shape3.Left _
Or Y - h1 > Shape3.Top + Shape3.Height Or Y + h2 < Shape3.Top) Then
Unload Picture3(Index)


End If

End If
End If


End Sub
这是我最开始做的~ 但很多功能无法实现
penguinhzf 2009-05-09
  • 打赏
  • 举报
回复
首先不清楚你"从站"是什么意思?不过可以将"从站"自定义为一个控件,或者一个变量来判断

给你个思路,假设"从站"是一个控件的话,在他的mousemove里可以实现拖动,然后再判断他的位置是否进入了shape1,shape2,shape3里,然后再根据你的意思来将"从站"移动到相应shape的位置上.

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧