private void ShowAndUpdateSeats_Load(object sender, EventArgs e) { try { int rows = GetRows(); int pointX = 30; lblCourse.Text = this.course; //pnlSeats.Controls.Clear(); pointX = 30; int pointY = 21; int i = 0; CreateFormColumnHeaders(pointX, pointY); //Set up dynamically rendered text boxes foreach (var myCourse in myCourses) { if (myCourse.CourseName.Equals(course)) { pointX = 30; pointY += 20 + i * 20; i++; for (int seatNo = 0; seatNo < 12; seatNo++) { CustomTextBox myTb = new CustomTextBox(); myTb.Width = 20; if (myCourse.Seats[seatNo] == 'B') { myTb.Text = "B"; } else { myTb.Text = (seatNo + 1).ToString(); } myTb.Location = new Point(pointX, pointY); myTb.Click += txtBox_Click; myTb.Seat = seatNo; myTb.ElementNumber = myCourse.Element; pnlSeats.Controls.Add(myTb); //myTextBoxes.Add(a); pointX += 30; } AddDateAndCostLabels(pointX, pointY, myCourse); } } pnlSeats.Show(); } catch (Exception) { MessageBox.Show(e.ToString()); } }