using System;
using System.Drawing;
using System.Windows.Forms;
namespace StudentRegistrationApplication
{
public partial class frmStudentRegistration : Form
{
private TextBox txtLastName, txtFirstName, txtMiddleName;
private RadioButton rbMale, rbFemale;
private ComboBox cbDay, cbMonth, cbYear;
private Button btnRegister;
private Label lblLastName, lblFirstName, lblMiddleName, lblGender, lblDob,
lblTitle;
public frmStudentRegistration()
{
InitializeComponent();
InitializeCustomComponents();
}
private void InitializeCustomComponents()
{
// Labels (Six (6) Labels, Font Size -> 12, Font Bold -> True)
lblTitle = new Label { Text = "Student Registration Form", Font = new
Font("Segoe UI", 14, FontStyle.Bold), Location = new Point(10, 10), Size = new
Size(250, 30) };
lblLastName = new Label { Text = "Last name *", Font = new Font("Segoe
UI", 12, FontStyle.Bold), Location = new Point(10, 50), Size = new Size(100, 20) };
lblFirstName = new Label { Text = "First name *", Font = new
Font("Segoe UI", 12, FontStyle.Bold), Location = new Point(10, 80), Size = new
Size(100, 20) };
lblMiddleName = new Label { Text = "Middle name *", Font = new
Font("Segoe UI", 12, FontStyle.Bold), Location = new Point(10, 110), Size = new
Size(120, 20) };
lblGender = new Label { Text = "Gender *", Font = new Font("Segoe UI",
12, FontStyle.Bold), Location = new Point(10, 140), Size = new Size(100, 20) };
lblDob = new Label { Text = "Date of birth *", Font = new Font("Segoe
UI", 12, FontStyle.Bold), Location = new Point(10, 170), Size = new Size(120,
20) };
// Textboxes (Three (3) Textboxes, Font Size -> 12)
txtLastName = new TextBox { Location = new Point(130, 50), Font = new
Font("Segoe UI", 12), Size = new Size(200, 25) };
txtFirstName = new TextBox { Location = new Point(130, 80), Font = new
Font("Segoe UI", 12), Size = new Size(200, 25) };
txtMiddleName = new TextBox { Location = new Point(130, 110), Font =
new Font("Segoe UI", 12), Size = new Size(200, 25) };
// Radio Buttons (Two (2) Radio buttons, Font Size -> 12)
rbMale = new RadioButton { Text = "Male", Location = new Point(130,
140), Font = new Font("Segoe UI", 12) };
rbFemale = new RadioButton { Text = "Female", Location = new Point(200,
140), Font = new Font("Segoe UI", 12) };
// Combo Boxes (Three (3) Combo boxes, Font Size -> 12)
cbDay = new ComboBox { Location = new Point(130, 170), Font = new
Font("Segoe UI", 12), Size = new Size(60, 25) };
cbMonth = new ComboBox { Location = new Point(195, 170), Font = new
Font("Segoe UI", 12), Size = new Size(60, 25) };
cbYear = new ComboBox { Location = new Point(260, 170), Font = new
Font("Segoe UI", 12), Size = new Size(70, 25) };
// Button (One (1) Button, Back Color -> Crimson, Flat Style -> Flat,
Font Size -> 12, Fore Color -> White)
btnRegister = new Button { Text = "Register student", Location = new
Point(10, 210), BackColor = Color.Crimson, FlatStyle = FlatStyle.Flat, ForeColor =
Color.White, Font = new Font("Segoe UI", 12), Size = new Size(150, 35) };
btnRegister.Click += BtnRegister_Click;
// Add Controls to the Form
Controls.Add(lblTitle);
Controls.Add(lblLastName);
Controls.Add(lblFirstName);
Controls.Add(lblMiddleName);
Controls.Add(lblGender);
Controls.Add(lblDob);
Controls.Add(txtLastName);
Controls.Add(txtFirstName);
Controls.Add(txtMiddleName);
Controls.Add(rbMale);
Controls.Add(rbFemale);
Controls.Add(cbDay);
Controls.Add(cbMonth);
Controls.Add(cbYear);
Controls.Add(btnRegister);
// Populate Combo Boxes using nested loops
PopulateComboBoxes();
}
private void PopulateComboBoxes()
{
cbDay.Items.Add("-Day-");
cbMonth.Items.Add("-Month-");
cbYear.Items.Add("-Year-");
// Nested loops (not efficient for this task)
for (int i = 0; i < 3; i++)
{
ComboBox currentComboBox;
int startValue, endValue;
switch (i)
{
case 0: // Day
currentComboBox = cbDay;
startValue = 1;
endValue = 31;
break;
case 1: // Month
currentComboBox = cbMonth;
startValue = 1;
endValue = 12;
break;
case 2: // Year
currentComboBox = cbYear;
startValue = 1900;
endValue = DateTime.Now.Year;
break;
default:
continue; // Should never happen
}
for (int j = startValue; j <= endValue; j++)
{
currentComboBox.Items.Add(j);
}
}
cbDay.SelectedIndex = 0;
cbMonth.SelectedIndex = 0;
cbYear.SelectedIndex = 0;
}
private void BtnRegister_Click(object sender, EventArgs e)
{
string lastName = txtLastName.Text;
string firstName = txtFirstName.Text;
string middleName = txtMiddleName.Text;
string gender = rbMale.Checked ? "Male" : "Female";
string day = cbDay.SelectedItem?.ToString();
string month = cbMonth.SelectedItem?.ToString();
string year = cbYear.SelectedItem?.ToString();
string dob = $"{day}/{month}/{year}";
string message = $"Last Name: {lastName}\nFirst Name: {firstName}\
nMiddle Name: {middleName}\nGender: {gender}\nDate of Birth: {dob}";
MessageBox.Show(message, "Student Information");
}
}
}