I have a "FlowLayoutPanel" and want to add series of "UserControl" to it:
mainPanel.Controls.Add(fx);
Every new usercontrol added after old one, I want to add new usercontrol before the previous usercontrol that was added how could I do this? I didn't find any functionality like mainPanel.Controls.AddAt(...)
or mainPanel.Controls.Add(index i, Control c)
or mainPanel.Controls.sort(...)
or ... .
You can use the SetChildIndex method. Something like (maybe you need to fiddle with the indecies):
var prevIndex = mainPanel.Controls.IndexOf(previouslyAdded)
mainPanel.Controls.Add(fx);
mainPanel.Controls.SetChildIndex(fx, prevIndex);
by the sounds of it you want to change the flowdirection attribute so that newest controls added are added to the top
flowLayoutPanel1.FlowDirection = FlowDirection.BottomUp;
or you could
Label label1 = new Label();
flowLayoutPanel1.Controls.Add(label1);
label1.BringToFront();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With