Answer the question
In order to leave comments, you need to log in
Grouping elements when adding Panel dynamically to tablelayout c# winforms?
When I try to create an element in the constructor, everything is correct, label and textbox are contained in one line (I set panel dock left, and textbox dock top). But when I try to create this element dynamically, I set the same properties, then these two elements are located in two lines ... How to fix this?
private void Button11_Click(object sender, EventArgs e)
{
oaoa++;
testttt.Add(new TableLayoutPanel() { Dock = DockStyle.Top , AutoSize = true, AutoSizeMode = AutoSizeMode.GrowAndShrink, AutoScroll = false });
testttt[oaoa].ColumnCount = 1;
testttt[oaoa].RowCount = 0;
testttt[oaoa].ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
testttt[oaoa].RowStyles.Add(new RowStyle(SizeType.AutoSize));
testttt[oaoa].RowCount++;
var panel = new Panel() { Dock = DockStyle.Top,AutoSizeMode = AutoSizeMode.GrowOnly,AutoSize = false };
panel.Controls.Add(new Label() { Text = "add1strokblock", AutoSize = true, Dock = DockStyle.Left});
panel.Controls.Add(new TextBox() { Dock = DockStyle.Top });
testttt[oaoa].Controls.Add(panel, 0, 0);
testttt[oaoa].RowCount++;
var panel1 = new Panel() { Dock = DockStyle.Top };
panel1.Controls.Add(new Label() { Text = "add2strokblock", AutoSize = true, Dock = DockStyle.Left });
panel1.Controls.Add(new TextBox() { Dock = DockStyle.Top });
testttt[oaoa].Controls.Add(panel1, 0, 1);
panel7.Controls.Add(testttt[oaoa]);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question