-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