Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

insert Usercontrol in FlowLayoutPanel

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 ?

like image 564
2Pietjuh2 Avatar asked Nov 07 '12 08:11

2Pietjuh2


People also ask

How do I add controls to FlowLayoutPanel?

To create a FlowLayoutPanel control at design-time, you simply drag and drop a FlowLayoutPanel control from Toolbox to a Form in Visual Studio.

How do I make my FlowLayoutPanel scrollable?

To view all the contents of flow layout panel by scrolling vertically, set AutoScroll property to True and don't forget to set WrapContents property to True. If the contents are to be viewed by scrolling horizontally, set AutoScroll property to True and don't forget to set WrapContents property to False.

What is user control in C#?

C# user control is defined as an implementation in programming language of C# to provide an empty control and this control can be leveraged to create other controls. This implementation provides additional flexibility to re-use controls in a large-scale web project.


1 Answers

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.

like image 168
Devraj Gadhavi Avatar answered Sep 20 '22 05:09

Devraj Gadhavi