Reputation: 473
I need the grid-like structure at the back of my main form, so using the TableLayoutPanel. Now, I need to place controls at "exact locations" on this panel. How can I achieve that ? I know how to put a control inside a cell, specifying the row & column#, but is there a way of managing rowspan, columnspan, and margins like in WPF grid ?
One more thing. I am hosting the TableLayoutPanel inside another Panel, and that 2nd Panel is basically inside a WindowsFormsHost in a WPF project.
This is how my TableLayoutPanel looks right now:
Upvotes: 0
Views: 2319
Reputation: 26
You can add Panel
to Cell
then add Button
to Panel
controls and set top
and left
for Button
.
Panel panel = new Panel();
Button button = new Button();
panel.Controls.Add(button);
panel.Dock = DockStyle.Fill;
button.Top = 5;
button.Left = 5;
tableLayoutPanel.Controls.Add(panel, 0,0);
tableLayoutPanel.SetColumnSpan(panel,2);
tableLayoutPanel.SetRowSpan(panel,2);
Upvotes: 0