拖动动态生成的控件
动态控件生成后,调用下面代码可以实现移动。
Public Sub canMove()
Dim vObj As Control
For Each vObj In Me.Controls
AddHandler vObj.MouseDown, AddressOf Controls_Down
AddHandler vObj.MouseMove, AddressOf Controls_Move
Next
End Sub
Private Sub Controls_Down(ByVal sender As Object, ByVal e As MouseEventArgs)
VPoint = New Point(e.X, e.Y)
obj = sender
sender.BringToFront()
End Sub
Private Sub Controls_Move(ByVal sender As Object, ByVal e As MouseEventArgs)
If Form.MouseButtons = MouseButtons.Left Then
If sender.left = 0 Then
CType(sender, Control).Location = New Point(0, sender.Top + e.Y - VPoint.Y)
endif
endif
endsub
再次生成其他控件时,调用canmove后移动时,控件乱飞。
帮忙看看!
[解决办法]
你在canMove()对每一个控件都设置了MouseDown、MouseMove处理函数,
For Each vObj In Me.Controls
AddHandler vObj.MouseDown, AddressOf Controls_Down
AddHandler vObj.MouseMove, AddressOf Controls_Move
Next
如果你只想让某些控件处理,应该改动canMove()
[解决办法]
是不是只有最后动态生成的那个控件移动是正确的啊?
[解决办法]
DrawApp为关键字在csdn下载中搜一下,看一下他是怎么解决的