Adding controls to panel via code - order they appear when using Dock-Top is backwards

0
0

Using the following code to add a few copies of a  user control to a panel:

ucMenuItem lo_MenuItem = new ucMenuItem();
lo_MenuItem.InitMenuItem(“New Batch”, “resource.wx/Wisej.Ext.FontAwesome/plus-square-o.svg?color=#F36736”, “Add”);
lo_MenuItem.MenuClicked += Lo_MenuItem_MenuClicked;
lo_MenuItem.Width = pnl_LeftMenu.Width;
lo_MenuItem.Dock = DockStyle.Top;
this.tt_Desktop.SetToolTip(lo_MenuItem, “Add a new batch”);
pnl_LeftMenu.Controls.Add(lo_MenuItem);
//pnl_LeftMenu.Controls.SetChildIndex(lo_MenuItem, 0);

 

if I’m adding lets say 5 of these above with different menu item names, they appear in the opposite order that I add them.

Is there a setting to make them go in order that they are added, or do I need to add them in reverse order ?

  • You must to post comments
0
0

I tried using SetChildIndex(its now commented out) – trying ascending and descending values – it didn’t make a difference, the controls were rendered in reverse order they were added to the panels.

  • You must to post comments
0
0

It’s not backward, it follows the z-index order like in winforms. You can change it using BringToFront, SendToBack, or Controls.SetChildIndex.

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.