Using this code to add a user control to a panel dynamically- the first one is always not aligned for some reason:
int li_numRoomCnt = 0;
for (int i = 0; i < 16; i++)
{
li_numRoomCnt++;ucRoom lo_Room = new ucRoom();
lo_Room.SetRoomInfo((ushort)li_numRoomCnt, “Room ” + li_numRoomCnt);
lo_Room.Width = flp_Rooms.Width;
lo_Room.Location = new System.Drawing.Point(0, (lo_Room.Height * i) + 2);
this.flp_Rooms.Controls.Add(lo_Room);
this.flp_Rooms.SuspendLayout();
this.flp_Rooms.Controls.SetChildIndex(lo_Room, i);
}
The user control just contains a label, a text box and a button. See screenshot
Try to remove this.flp_Rooms.SuspendLayout(); It stops the layout engine, it should be used in pair with ResumeLayout() when needed. In this case it doesn’t look like it’s needed.
Please login first to submit.