我使用的是简单Panel
,并在按钮点击事件中添加了两个标签。
代码看起来像。(ShowAllItemContainer
是Panel
名称。)
Label l = new Label();
l.Text = "Hello1";
Label ll = new Label();
ll.Text = "Hello2";
ll.Margin = new Padding(50,50, 0, 0);
ShowAllItemContainer.Controls.Add(l);
ShowAllItemContainer.Controls.Add(ll);
但输出只显示一个lable
,第一个。
我尝试设置填充但输出保持不变。
我想在Panel中垂直添加标签 。我怎么能这样做?
答案 0 :(得分:1)
您必须指定位置
Label l = new Label();
l.Text = "Hello1";
l.Location = new Point(0, 0);
Label ll = new Label();
ll.Text = "Hello2";
l.Location = new Point(0, 20);
ll.Margin = new Padding(50, 50, 0, 0);
ShowAllItemContainer.Controls.Add(l);
ShowAllItemContainer.Controls.Add(ll);
您也可以使用flowlayout面板
来实现它Label l = new Label();
l.Text = "Hello1";
Label ll = new Label();
ll.Text = "Hello2";
flowLayoutPanel1.Controls.Add(l);
flowLayoutPanel1.Controls.Add(ll);
flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;