-1
我在它的父面板内有一个面板,允许我移动。我希望它停止移动,然后它会脱离父面板。什么是完成这个最好的方法。我也动态地添加面板。面板边缘检测,在出界之前停止
更新: 以下是进入“MyPanel”面板的代码。 “MyPanel”和“Panel”之间的区别仅在于我添加了一个边框并且可以移动它。 “CoolMove”来自他人在网上找到的答案。我添加一个“MyPanel1”来形成,然后添加另一个“MyPanel2”,并允许它只在“MyPanel1”上移动。因此,我希望“MyPanel2”完全保留在“MyPanel1”的范围内。我正在努力获得正确的代码来实现这一点。
Private allowCoolMove As Boolean = False
Private myCoolPoint As New Point
Public Overridable Sub MyPanel_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
'If panel is ontop of Stock panel, then allow manual moving
If Me.Parent.Name.StartsWith("S") Then
allowCoolMove = True
myCoolPoint = New Point(e.X, e.Y)
Me.Cursor = Cursors.SizeAll
Me.BringToFront()
ElseIf Not Me.Parent.Name.Contains("keyR") Then
DoDragDrop(Me, DragDropEffects.Move)
End If
End Sub
Private Sub MyPanel_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
If allowCoolMove = True Then
Me.Location = New Point(Me.Location.X + e.X - myCoolPoint.X, Me.Location.Y + e.Y - myCoolPoint.Y)
End If
End Sub
Private Sub MyPanel_MouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp
allowCoolMove = False
Me.Cursor = Cursors.Default
End Sub
我无法正常工作。我把它放在MouseMove事件中(这是我的移动代码的地方),它只是阻止它移动? – goomba454
@ goomba454:请用您的新代码更新您的问题。 –
好吧,我更新了我正在尝试使用的代码。 – goomba454