문제

I am using simple Panel and added two labels on event of button click.

Code looks like.(ShowAllItemContainer is Panel name.)

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);

But output displaying only one lable, the first one.

I tried by setting padding but output remains same.

I want to add Labels vertically in Panel. How can I do that?

도움이 되었습니까?

해결책

You have to specify the location

 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);

Also you can achieve it using flowlayout panel

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;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top