Hi.. Can anybody help mi fixing a bug using a Usercontrol as child in flowlayoutpanel?
Usercontrol = Group
The problem is only the dragging drop part where for example i have made Group1, Group2, Group3,
when I drag card1 the only arrangement I can do is (Group2,Group3,Group1) where I drag Group1 at the left side of Group 3, if I put Group1 in between of Group2 and Group3, it does not work.
again.
when i drag Group2, the only arrangement I can do is (Group1,Group3,Group2)
when I drag Group3 in between of Group1 and Group2 or in front of Group1.. the arrangement would remain (Group1,Group3,Group2).
![Name: Untitled.png
Views: 7
Size: 8.7 KB]()
In the Add cards.. I dont have problems of the controls.. the problem is only the Add group which is a usercontrol I created.
Here are the codes for Adding Groupbox:
In my Module: note Card is the name of my UserControl
Public carddragcursor As Cursor, carddragtype As Type
Public cardgetsource As Card
Public Sub Card_DragEnter(sender As Object, e As DragEventArgs)
If e.AllowedEffect = DragDropEffects.Move AndAlso e.Data.GetDataPresent(carddragtype) Then
e.Effect = DragDropEffects.Move
cardgetsource = CType(e.Data.GetData(carddragtype), Card)
End If
End Sub
Public Sub Card_GiveFeedback(sender As Object, e As GiveFeedbackEventArgs)
e.UseDefaultCursors = False
Cursor.Current = carddragcursor
End Sub
In my Form1
Dim i As Integer = 1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim cards As New Card
cards.Location = New System.Drawing.Point(58, 38)
cards.Size = New System.Drawing.Size(206, 324)
cards.Name = "Group" & i.ToString
cards.FlowLayoutCard.Name = "Flow" & i.ToString
cards.GroupBox1.Text = "Group" & i.ToString
Me.FlowLayoutPanel1.Controls.Add(cards)
AddHandler cards.FlowLayoutCard.GiveFeedback, AddressOf FlowLayoutPanel1_GiveFeedback
AddHandler cards.FlowLayoutCard.DragEnter, AddressOf FlowLayoutPanel1_DragEnter
AddHandler cards.FlowLayoutCard.DragDrop, AddressOf flowLayoutPanel1_DragDrop
AddHandler FlowLayoutPanel1.GiveFeedback, AddressOf Card_GiveFeedback
AddHandler FlowLayoutPanel1.DragEnter, AddressOf Card_DragEnter
AddHandler FlowLayoutPanel1.DragDrop, AddressOf Card_DragDrop
AddHandler cards.MouseDown, AddressOf Card_Mousedown
i += 1
End Sub
Public Sub Card_Mousedown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dim source As Card = CType(sender, Card)
Using bmp As New Bitmap(source.Width, source.Height)
source.DrawToBitmap(bmp, New Rectangle(Point.Empty, source.Size))
carddragcursor = New Cursor(bmp.GetHicon)
End Using
carddragtype = source.GetType
FlowLayoutPanel1.DoDragDrop(source, DragDropEffects.Move)
carddragcursor.Dispose()
End Sub
Private Sub Card_DragDrop(sender As Object, e As DragEventArgs)
' Dim source As Card = CType(e.Data.GetData(carddragtype), Card)
Dim _destination As FlowLayoutPanel = DirectCast(sender, FlowLayoutPanel)
Dim _source As FlowLayoutPanel = DirectCast(cardgetsource.Parent, FlowLayoutPanel)
If _source IsNot _destination Then
' Add control to panel
_destination.Controls.Add(cardgetsource)
' Reorder
Dim p As Point = _destination.PointToClient(New Point(e.X, e.Y))
Dim item = _destination.GetChildAtPoint(p)
Dim index As Integer = _destination.Controls.GetChildIndex(item, False)
_destination.Controls.SetChildIndex(cardgetsource, index)
' Invalidate to paint!
_destination.Invalidate()
_source.Invalidate()
Else
' Just add the control to the new panel.
' No need to remove from the other panel, this changes the Control.Parent property.
Dim p As Point = _destination.PointToClient(New Point(e.X, e.Y))
Dim item = _destination.GetChildAtPoint(p)
Dim index As Integer = _destination.Controls.GetChildIndex(item, False)
_destination.Controls.SetChildIndex(cardgetsource, index)
_destination.Invalidate()
End If
End Sub
Usercontrol = Group
The problem is only the dragging drop part where for example i have made Group1, Group2, Group3,
when I drag card1 the only arrangement I can do is (Group2,Group3,Group1) where I drag Group1 at the left side of Group 3, if I put Group1 in between of Group2 and Group3, it does not work.
again.
when i drag Group2, the only arrangement I can do is (Group1,Group3,Group2)
when I drag Group3 in between of Group1 and Group2 or in front of Group1.. the arrangement would remain (Group1,Group3,Group2).
In the Add cards.. I dont have problems of the controls.. the problem is only the Add group which is a usercontrol I created.
Here are the codes for Adding Groupbox:
In my Module: note Card is the name of my UserControl
Public carddragcursor As Cursor, carddragtype As Type
Public cardgetsource As Card
Public Sub Card_DragEnter(sender As Object, e As DragEventArgs)
If e.AllowedEffect = DragDropEffects.Move AndAlso e.Data.GetDataPresent(carddragtype) Then
e.Effect = DragDropEffects.Move
cardgetsource = CType(e.Data.GetData(carddragtype), Card)
End If
End Sub
Public Sub Card_GiveFeedback(sender As Object, e As GiveFeedbackEventArgs)
e.UseDefaultCursors = False
Cursor.Current = carddragcursor
End Sub
In my Form1
Dim i As Integer = 1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim cards As New Card
cards.Location = New System.Drawing.Point(58, 38)
cards.Size = New System.Drawing.Size(206, 324)
cards.Name = "Group" & i.ToString
cards.FlowLayoutCard.Name = "Flow" & i.ToString
cards.GroupBox1.Text = "Group" & i.ToString
Me.FlowLayoutPanel1.Controls.Add(cards)
AddHandler cards.FlowLayoutCard.GiveFeedback, AddressOf FlowLayoutPanel1_GiveFeedback
AddHandler cards.FlowLayoutCard.DragEnter, AddressOf FlowLayoutPanel1_DragEnter
AddHandler cards.FlowLayoutCard.DragDrop, AddressOf flowLayoutPanel1_DragDrop
AddHandler FlowLayoutPanel1.GiveFeedback, AddressOf Card_GiveFeedback
AddHandler FlowLayoutPanel1.DragEnter, AddressOf Card_DragEnter
AddHandler FlowLayoutPanel1.DragDrop, AddressOf Card_DragDrop
AddHandler cards.MouseDown, AddressOf Card_Mousedown
i += 1
End Sub
Public Sub Card_Mousedown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dim source As Card = CType(sender, Card)
Using bmp As New Bitmap(source.Width, source.Height)
source.DrawToBitmap(bmp, New Rectangle(Point.Empty, source.Size))
carddragcursor = New Cursor(bmp.GetHicon)
End Using
carddragtype = source.GetType
FlowLayoutPanel1.DoDragDrop(source, DragDropEffects.Move)
carddragcursor.Dispose()
End Sub
Private Sub Card_DragDrop(sender As Object, e As DragEventArgs)
' Dim source As Card = CType(e.Data.GetData(carddragtype), Card)
Dim _destination As FlowLayoutPanel = DirectCast(sender, FlowLayoutPanel)
Dim _source As FlowLayoutPanel = DirectCast(cardgetsource.Parent, FlowLayoutPanel)
If _source IsNot _destination Then
' Add control to panel
_destination.Controls.Add(cardgetsource)
' Reorder
Dim p As Point = _destination.PointToClient(New Point(e.X, e.Y))
Dim item = _destination.GetChildAtPoint(p)
Dim index As Integer = _destination.Controls.GetChildIndex(item, False)
_destination.Controls.SetChildIndex(cardgetsource, index)
' Invalidate to paint!
_destination.Invalidate()
_source.Invalidate()
Else
' Just add the control to the new panel.
' No need to remove from the other panel, this changes the Control.Parent property.
Dim p As Point = _destination.PointToClient(New Point(e.X, e.Y))
Dim item = _destination.GetChildAtPoint(p)
Dim index As Integer = _destination.Controls.GetChildIndex(item, False)
_destination.Controls.SetChildIndex(cardgetsource, index)
_destination.Invalidate()
End If
End Sub