17

I have a FlowLayoutPanel and several UserControls. Now I want one controll to be always at the bottom of my FlowLayoutPanel. So I want to add my UserControl just above the lowest controll. Is there an easy way to insert user controls in a FlowLayoutPanel?

I'm currently thinking about removing the control at the bottom, and adding the control I want to add and add the bottom control again. But this I do not think this is really the best way. Is there anyone here who could help me with some information on how to do this ?

Picrofo Software
  • 5,475
  • 3
  • 23
  • 37
2Pietjuh2
  • 173
  • 1
  • 1
  • 5
  • 1
    Is it easy to switch from WinForms to WPF, or do I need to learn a lot before you can do that? – 2Pietjuh2 Nov 07 '12 at 08:20
  • WPF is pretty easy to pick up. For the most part you can use it exactly the same way you use Forms and take on some of it's more complex features as you require them. – Spencer Ruport Nov 08 '12 at 07:59

2 Answers2

14

Yes, you can set the Index of a Control OR User-Control in Flow-Layout Panel.

//flPanel is your flow-layout panel...
flPanel.Contorls.Add(ctrl1); //ctrl1 can be any control or user control
flPanel.Contorls.Add(ctrl2); //ctrl2 can be any control or user control
flPanel.Controls.SetChildIndex(ctrl1, flPanel.Controls.GetChildIndex(ctrl2) + 1);

This way, your ctrl1 would be at bottom though it was added first into your Flow-Layout Panel.

If you have more Controls, and you are toggling their visibility in different events, then you will have to set Index for each Control every time.

I suggest to place your Control in Panel and add Panel in your Flow-Layout Panel.

Devraj Gadhavi
  • 3,541
  • 3
  • 38
  • 67
0

This has nothing to do with WinForms/WPF. You are trying to use a panel for flowing layout for something that is clearly not meant to use flow.

You should change your layoutpanels accordingly. Try using a flowlayout on the items where you need the flow, then putting that panel inside another panel which also host your bottom panel.

helgeheldre
  • 1,081
  • 11
  • 20
  • That is petty much what i do. I have a usercontrol which hosts a `flowLayoutPanel` inside that panel I load other controls. My question is: How can I add other controls on a different place than on the bottom? (I want them placed one above the bottom control:)) – 2Pietjuh2 Nov 07 '12 at 10:13
  • You should have a panel that isent flowLayoutPanel as the outermost panel, on that panel you add your flowLayoutPanel and then your two other controls. – helgeheldre Nov 07 '12 at 10:16