public void PopulateSelectionScreen(string title, string[] categoryNames, int num_questions, int base_value, int level) { int num_qs = num_questions; int num_cat = categoryNames.Length; lblTitle.Text = title; int Main_Xloc = this.Location.X; int Main_Yloc = this.Location.Y; Main_Xloc = 0; Main_Yloc = 0; lblTitle.Refresh(); lblTitle.Location = new Point((int)(this.Width*0.5 - lblTitle.Width*0.5), (int)(Main_Yloc + 1)); QPanel.Location = new Point(Main_Xloc + 10, lblTitle.Location.Y + lblTitle.Height + 10); QPanel.Width = this.Width - 20; QPanel.Height = this.Height - QPanel.Location.Y - (grpScores.Height); //hide panel blanks the screen HidePanel.Location = this.Location; HidePanel.Width = this.Width; HidePanel.Height = this.Height; HidePanel.BringToFront(); //remove any old items in the groupbox QPanel.Controls.Clear(); foreach (Control c in QPanel.Controls) { QPanel.Controls.Remove(c); } //get groupbox location and size Point grpLocation = QPanel.Location; int grpWidth = QPanel.Width; int grpHeight = QPanel.Height; int catWidth = (int)((grpWidth - 20) / num_cat); //add new headings int LabelHeight = 0; for (int i = 0; i < num_cat; i++) { GrowLabel L = new GrowLabel(); //Label L = new Label(); L.Name = "CatLabel" + i.ToString(); //L.Size = new Size(catWidth, 30); L.Width = catWidth; L.Location = new Point(grpLocation.X + (i * catWidth), 5); L.Text = categoryNames[i]; L.TextAlign = ContentAlignment.MiddleCenter; L.BorderStyle = SampleHeading.BorderStyle; L.BackColor = SampleHeading.BackColor; L.ForeColor = SampleHeading.ForeColor; L.Font = SampleHeading.Font; QPanel.Controls.Add(L); //save max label height if (LabelHeight < L.Height) { LabelHeight = L.Height; } } //adjust heights to match for (int i = 0; i < num_cat; i++) { ((GrowLabel)QPanel.Controls["CatLabel" + i.ToString()]).AllowResize = false; ((GrowLabel)QPanel.Controls["CatLabel" + i.ToString()]).Height = LabelHeight; } //add buttons int btnHeight = (int)((grpHeight - (20 + LabelHeight)) / num_qs); for (int i = 0; i < num_cat; i++) { for (int j = 0; j < num_qs; j++) { Button B = new Button(); B.Name = "btnQ" + ((i + 1).ToString() + (j + 1).ToString()).ToString(); B.Size = new Size(catWidth, btnHeight); B.Location = new Point(grpLocation.X + (i * catWidth), LabelHeight + 5 + (j * btnHeight)); B.Text = ((j + 1) * base_value).ToString(); B.TextAlign = ContentAlignment.MiddleCenter; B.BackColor = SampleQuestion.BackColor; B.ForeColor = SampleQuestion.ForeColor; B.Font = SampleQuestion.Font; B.Tag = new string[] { level.ToString(), (i + 1).ToString() + (j + 1).ToString() }; B.Click += new EventHandler(btnQ_Click); QPanel.Controls.Add(B); } } //add scores int scoreWidth = (int)(this.Width / 8); int scoreHeight = grpScores.Height - 4; grpScores.Width = this.Width; grpScores.Location = new Point(this.Location.X,QPanel.Location.Y + QPanel.Height); for (int i = 1; i <= 8; i++) { grpScores.Controls["score" + i.ToString()].Width = scoreWidth; grpScores.Controls["score" + i.ToString()].Location = new Point((i-1)*scoreWidth,2); grpScores.Controls["score" + i.ToString()].Height = scoreHeight; } grpScores.Visible = true; webBrowser1.Visible = false; if (!TitleShown) { //open title page if it has not been shown yet ShowTitle(true); } }