Here is a quick and dirty example of dragging and dropping panels into a TableLayoutPanel:
Code:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim tlpContainer = New TableLayoutPanel() With {
.AllowDrop = True,
.BorderStyle = BorderStyle.FixedSingle,
.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset,
.ColumnCount = 2,
.Location = New Point(5, 5),
.RowCount = 2,
.Size = New Size(300, 300)
}
tlpContainer.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 50))
tlpContainer.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 50))
tlpContainer.RowStyles.Add(New RowStyle(SizeType.Percent, 50))
tlpContainer.RowStyles.Add(New RowStyle(SizeType.Percent, 50))
AddHandler tlpContainer.DragEnter, AddressOf TableLayoutPanel_DragEnter
AddHandler tlpContainer.DragDrop, AddressOf TableLayoutPanel_DragDrop
Controls.Add(tlpContainer)
Dim colors = {Color.Yellow, Color.Blue, Color.Red, Color.Green}
For index = 0 To colors.Length - 1
Dim panel = New Panel() With {
.BackColor = colors(index),
.Location = New Point(tlpContainer.Right + 15, tlpContainer.Top + (index * 55)),
.Size = New Size(50, 50)
}
AddHandler panel.MouseDown, AddressOf Panel_MouseDown
Controls.Add(panel)
Next
End Sub
Private Sub Panel_MouseDown(sender As Object, e As MouseEventArgs)
If (e.Button = MouseButtons.Left) Then
Dim panel = DirectCast(sender, Panel)
panel.DoDragDrop(panel, DragDropEffects.Move)
End If
End Sub
Private Sub TableLayoutPanel_DragEnter(sender As Object, e As DragEventArgs)
If (e.Data.GetDataPresent(GetType(Panel))) Then
e.Effect = DragDropEffects.Move
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub TableLayoutPanel_DragDrop(sender As Object, e As DragEventArgs)
If (e.Data.GetDataPresent(GetType(Panel))) Then
Dim panel = DirectCast(e.Data.GetData(GetType(Panel)), Panel)
Dim tlpContainer = DirectCast(sender, TableLayoutPanel)
panel.Dock = DockStyle.Fill
tlpContainer.Controls.Add(panel)
End If
End Sub
End Class
But I don't think this is exactly what you want in that it is not specifying which cell to drop the control in.