17

I have a flowlayout control in winforms, i have set its flow direction to TopDown but it keeps adding controls from left to right, autoscroll is also set to true.

flowLayoutPanel1.Controls.Clear();    
Label labelInput = new Label();
ListBox listBoxNewInput = new ListBox();

//Initialize label's property
labelInput.Text = " #" + Convert.ToInt32(sequence);
labelInput.AutoSize = true;

//Initialize textBoxes Property
listBoxNewInput.HorizontalScrollbar = false;

listBoxNewInput.Items.Add(efforts);
//Add the newly created text box to the list of input text boxes
inputTextBoxesList.Add(listBoxNewInput);

//Add the labels and text box to the form
flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
flowLayoutPanel1.Controls.Add(labelInput);
flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
flowLayoutPanel1.Controls.Add(listBoxNewInput);
Sandy
  • 11,332
  • 27
  • 76
  • 122
PUG
  • 4,301
  • 13
  • 73
  • 115
  • what i want is that if they dont fit vertically it should make a scroll bar, but it puts them on the right – PUG Oct 12 '11 at 14:22

1 Answers1

30

Set the WrapContents property of the flowLayoutPanel1 to false, it will not allow to move those controls on the right if they don't fit. In order to be able to scroll clipped content you can set AutoScroll property to true

Here is the code:

flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
flowLayoutPanel1.WrapContents = false;
flowLayoutPanel1.AutoScroll = true;
flowLayoutPanel1.Controls.Add(labelInput);
flowLayoutPanel1.Controls.Add(listBoxNewInput);
username
  • 3,378
  • 5
  • 44
  • 75
  • 1
    OMG it would take weeks for me to solve this without someone directly say. cheers – ErTR Jan 25 '16 at 22:51