Dynamically adding user object to panel - first one not aligned

Answered
0
0

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

Attachment
  • You must to post comments
Best Answer
0
0

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.

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.