How do I align controls in FlowLayoutPanel properly

3k Views Asked by At

I am currently trying to play around with c#. I want to create a simple GUI containing (as minimal example) three labels. The first two should be aligned from top to buttom and the third one to the right of these two button.

I have this in a panel, like

Label p_LabelX = new Label();
p_LabelX.Text = "I am to the right";

FlowLayoutPanel p_ButtonLayout = new FlowLayoutPanel();
p_ButtonLayout.Width = 200;
Label p_Label1 = new Label();
p_Label1.Text = "I am upper left";

Label p_Label2 = new Label();
p_Label2.Text = "I am lower left";

p_ButtonLayout.Controls.Add(p_Label1);
p_ButtonLayout.Controls.Add(p_Label2);

FlowLayoutPanel p_MainLayout = new FlowLayoutPanel();
p_MainLayout.FlowDirection = FlowDirection.LeftToRight;
p_MainLayout.WrapContents = false;
p_MainLayout.AutoScroll = true;
p_MainLayout.Controls.Add(p_ButtonLayout);
p_MainLayout.Controls.Add(p_LabelX);

this.Controls.Add(p_MainLayout);

With this code, it kind of works, but I have some scrollbars and the mainlayout is not fullscreen within the panel. However, if I skip the AutoScroll line, the scrollbars are gone and the layout seems to be fullscreen, but the right button is not visible.

Any suggestions?

0

There are 0 best solutions below