首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

怎样来用鼠标拖动控件数组解决思路

2012-04-13 
怎样来用鼠标拖动控件数组有个控件数组image1(N)排列在窗体上,本想用个容器装在里面,然后移动容器,结果容

怎样来用鼠标拖动控件数组
有个控件数组   image1(N)   排列在窗体上,本想用个容器装在里面,然后移动容器,结果容器的宽高溢出,怎么样来整体移动,给个代码先,谢过了

[解决办法]
还是用容器,坐标溢出应该是数据变量使用不当的问题,比如
debug.print 256 * 256
溢出
debug.print 256& * 256&
正常
[解决办法]
使用容器的这个思路没问题,仔细查查
[解决办法]
http://www.yesky.com/117/201117.shtml
[解决办法]
100分哪..................
[解决办法]
看在高分的份上,背着老板偷偷写下如下代码,并运行调试过。
picture1作为容器,增加一个shape1(矩形)控件,设计时shape1.Visible=true ,鼠标移到picture1靠左地方,光标变为四向光标,表示可以移动,点击拾取容器,移动后再点击放下容器。

Dim blDrag, blEnDrag As Boolean

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not blDrag Then Exit Sub
Shape1.Left = X
Shape1.Top = Y
Picture1.Left = X
Picture1.Top = Y
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not blDrag Then Exit Sub
Picture1.Left = Shape1.Left
Picture1.Top = Shape1.Top
Picture1.Visible = True
Shape1.Visible = False
blDrag = False
MousePointer = 0
End Sub

Private Sub Picture1_Click()
If Not blEnDrag Then Exit Sub
blDrag = True
Shape1.Width = Picture1.Width
Shape1.Height = Picture1.Height
Picture1.Visible = False
Shape1.Visible = True
MousePointer = 5
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X < 200 And X > 50 Then
MousePointer = 5
blEnDrag = True
Else
MousePointer = 0
blEnDrag = False
End If
End Sub


[解决办法]
用容器的思路是对的

然后就用drag方法,会激发drag over,drag drop两个方法

[解决办法]
Picture1是容器,左键点中它拖动:
Private mX As Long, mY As Long
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
mX = X
mY = Y
End If
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
Picture1.Move Picture1.Left + (X - mX), Picture1.Top + (Y - mY)
End If
End Sub

热点排行