Hi All,
I have code that was provided by MattP (thank you) from thread http://www.vbforums.com/showthread.p...nel-to-another
I have adapted the code to work with my needs and all is well, however I wish to know how can I make the other controls "move" out of the cursors way.
What I mean by that is for example on an iphone, when you move your app icons around, if you go to a gap between 2 buttons the ones after that point move so you can clearly see where its going, I want to replicate that kind of effect.
The code below gets most the way there, and at the time of the other thread was all I needed, so I have started another thread for the additional question.
Now I know little about how drag and drop works behind the scences despite reading vast data on MSDN about it.
I assume (again assume) I would need to put code in the feedback event?
Thank you for any advise
I have code that was provided by MattP (thank you) from thread http://www.vbforums.com/showthread.p...nel-to-another
I have adapted the code to work with my needs and all is well, however I wish to know how can I make the other controls "move" out of the cursors way.
What I mean by that is for example on an iphone, when you move your app icons around, if you go to a gap between 2 buttons the ones after that point move so you can clearly see where its going, I want to replicate that kind of effect.
The code below gets most the way there, and at the time of the other thread was all I needed, so I have started another thread for the additional question.
Now I know little about how drag and drop works behind the scences despite reading vast data on MSDN about it.
I assume (again assume) I would need to put code in the feedback event?
Thank you for any advise
Code:
1.Public Class Form1
2.
3. Private ButtonIndex = 0
4. Private DragDropCursor As Cursor
5.
6. Private Sub OnCreateButtonClick(sender As Object, e As EventArgs) Handles CreateButton.Click
7.
8. ButtonIndex += 1
9.
10. Dim button = New Button
11. button.Name = "Button" & ButtonIndex
12. button.Text = "Test " & ButtonIndex
13. button.Parent = LeftFlowLayoutPanel
14. AddHandler button.MouseDown, AddressOf OnButtonMouseDown
15.
16. End Sub
17.
18. Private Sub OnButtonMouseDown(sender As Object, e As MouseEventArgs)
19.
20. Dim button = DirectCast(sender, Button)
21.
22. Using bmp As New Bitmap(button.Width, button.Height)
23. button.DrawToBitmap(bmp, New Rectangle(Point.Empty, button.Size))
24. DragDropCursor = New Cursor(bmp.GetHicon)
25. End Using
26.
27. button.Parent.DoDragDrop(button, DragDropEffects.Move)
28.
29. End Sub
30.
31. Private Sub OnFlowLayoutPanelDragEnter(sender As Object, e As DragEventArgs) _
32. Handles LeftFlowLayoutPanel.DragEnter, RightFlowLayoutPanel.DragEnter
33.
34. If e.AllowedEffect = DragDropEffects.Move AndAlso e.Data.GetDataPresent(GetType(Button)) Then
35. e.Effect = DragDropEffects.Move
36. End If
37.
38. End Sub
39.
40. Private Sub OnFlowLayoutPanelDragDrop(sender As Object, e As DragEventArgs) _
41. Handles LeftFlowLayoutPanel.DragDrop, RightFlowLayoutPanel.DragDrop
42.
43. Dim button = DirectCast(e.Data.GetData(GetType(Button)), Button)
44. Dim destPanel = DirectCast(sender, FlowLayoutPanel)
45. destPanel.Controls.Add(button)
46. Dim targetLoc = destPanel.GetChildAtPoint(destPanel.PointToClient(New Point(e.X, e.Y)))
47.
48. If targetLoc IsNot Nothing Then
49. Dim idx = destPanel.Controls.GetChildIndex(targetLoc)
50. destPanel.Controls.SetChildIndex(button, idx)
51. End If
52.
53. End Sub
54.
55. Private Sub OnFlowLayoutPanelGiveFeedback(sender As Object, e As GiveFeedbackEventArgs) _
56. Handles LeftFlowLayoutPanel.GiveFeedback, RightFlowLayoutPanel.GiveFeedback
57.
58. e.UseDefaultCursors = False
59. Cursor.Current = DragDropCursor
60.
61. End Sub
62.End Class