Answer to Question #325612 in C# for Terry

Question #325612

Instructions:


1. Create a Windows application that will ask the user to enter a student’s information, then display all of


them in a message box when the button is clicked. The application should include the following controls


and their properties:


Control Properties


Three (3) Textboxes


Two (2) Radio buttons Font Size -> 12


Three (3) Combo boxes


One (1) Button Back Color -> Crimson


Flat Style -> Flat


Font Size -> 12


Fore Color -> White


Six (6) Labels Font Size -> 12


Font Bold -> True


2. The program should meet the following specifications:


• Use CamelCase in naming controls.


• Use looping statement to add items on the three (3) combo boxes:


o Day is from 1 to 31;


o Month is from 1 to 12; and


o Year is from 1900 to current year.


• Use a decision statement to determine what combo box value is selected by the user.


3. Name the project as StudentRegistrationApplication and the class or form as


frmStudentRegistration.

1
Expert's answer
2022-04-08T03:47:36-0400
using System;
using System.Data;
using System.Linq;
using System.Windows.Forms;


namespace StudentRegistrationApplication
{




    public partial class frmStudentRegistration : Form
    {
        public frmStudentRegistration()
        {
            InitializeComponent();


            for (int i = 1900; i < DateTime.Today.Year; i++)
            {
                YearOfBirthComboBox.Items.Add(i);
            }
            for (int i = 1; i < 32; i++)
            {
                DayOfBirthComboBox.Items.Add(i);
            }
            for (int i = 1; i < 13; i++)
            {
                MonthOfBirthComboBox.Items.Add(i);
            }
        }


        private void ShowButton_Click(object sender, EventArgs e)
        {
            string gender = Controls.OfType<RadioButton>().Where(x => x.Checked).Select(x => x.Text).First();
            int year = int.Parse(YearOfBirthComboBox.SelectedItem.ToString());
            int month = int.Parse(MonthOfBirthComboBox.SelectedItem.ToString());
            int day = int.Parse(DayOfBirthComboBox.SelectedItem.ToString());
            Student student = new Student(FirstNameTextBox.Text, LastNameTextBox.Text, FacultyTextBox.Text, gender, year,month, day);
            MessageBox.Show(
       "Do you want to register such a student:\n" +
       $"{student}",
       "Message",
       MessageBoxButtons.OK,
       MessageBoxIcon.Information,
       MessageBoxDefaultButton.Button1,
       MessageBoxOptions.DefaultDesktopOnly);
        }
    }
    class Student
    {
        public string FirsName { get; set; }
        public string LastName { get; set; }
        public string Faculty { get; set; }
        public string Gender { get; set; }
        public int YearOfBirth { get; set; }
        public int MonthOfBirth { get; set; }
        public int DayOfBirth { get; set; }
        public Student(string firstName, string lastName, string faculty, string gender, int yearOfBirth, int monthOfBirth, int dayOfBirth)
        {
            FirsName = firstName;
            LastName = lastName;
            Faculty = faculty;
            Gender = gender;
            YearOfBirth = yearOfBirth;
            MonthOfBirth = monthOfBirth;
            DayOfBirth = dayOfBirth;
        }
        public override string ToString()
        {
            return $"FirstName: {FirsName}, LastName: {LastName}, Faculty: {Faculty}, Gender: {Gender},\n " +
                $"YearOfBirth: {YearOfBirth}, MonthOfBirth: {MonthOfBirth}, DayOfBirth: {DayOfBirth}";
        }
    }
}

namespace StudentRegistrationApplication
{
    partial class frmStudentRegistration
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;


        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }


        #region Windows Form Designer generated code


        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.FirstNameTextBox = new System.Windows.Forms.TextBox();
            this.LastNameTextBox = new System.Windows.Forms.TextBox();
            this.FacultyTextBox = new System.Windows.Forms.TextBox();
            this.MaleRadioButton = new System.Windows.Forms.RadioButton();
            this.FemaleRadioButton = new System.Windows.Forms.RadioButton();
            this.DayOfBirthComboBox = new System.Windows.Forms.ComboBox();
            this.MonthOfBirthComboBox = new System.Windows.Forms.ComboBox();
            this.YearOfBirthComboBox = new System.Windows.Forms.ComboBox();
            this.ShowButton = new System.Windows.Forms.Button();
            this.FirstNameLabel = new System.Windows.Forms.Label();
            this.LastNameLabel = new System.Windows.Forms.Label();
            this.GenderLabel = new System.Windows.Forms.Label();
            this.FacultyLabel = new System.Windows.Forms.Label();
            this.MonthOfBirthLabel = new System.Windows.Forms.Label();
            this.YearOfBirthLabel = new System.Windows.Forms.Label();
            this.DayOfBirthLabel = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // FirstNameTextBox
            // 
            this.FirstNameTextBox.Location = new System.Drawing.Point(183, 40);
            this.FirstNameTextBox.Name = "FirstNameTextBox";
            this.FirstNameTextBox.Size = new System.Drawing.Size(190, 20);
            this.FirstNameTextBox.TabIndex = 0;
            // 
            // LastNameTextBox
            // 
            this.LastNameTextBox.Location = new System.Drawing.Point(183, 83);
            this.LastNameTextBox.Name = "LastNameTextBox";
            this.LastNameTextBox.Size = new System.Drawing.Size(190, 20);
            this.LastNameTextBox.TabIndex = 1;
            // 
            // FacultyTextBox
            // 
            this.FacultyTextBox.Location = new System.Drawing.Point(183, 129);
            this.FacultyTextBox.Name = "FacultyTextBox";
            this.FacultyTextBox.Size = new System.Drawing.Size(190, 20);
            this.FacultyTextBox.TabIndex = 2;
            // 
            // MaleRadioButton
            // 
            this.MaleRadioButton.AutoSize = true;
            this.MaleRadioButton.Location = new System.Drawing.Point(183, 165);
            this.MaleRadioButton.Name = "MaleRadioButton";
            this.MaleRadioButton.Size = new System.Drawing.Size(48, 17);
            this.MaleRadioButton.TabIndex = 3;
            this.MaleRadioButton.TabStop = true;
            this.MaleRadioButton.Text = "Male";
            this.MaleRadioButton.UseVisualStyleBackColor = true;
            // 
            // FemaleRadioButton
            // 
            this.FemaleRadioButton.AutoSize = true;
            this.FemaleRadioButton.Location = new System.Drawing.Point(288, 165);
            this.FemaleRadioButton.Name = "FemaleRadioButton";
            this.FemaleRadioButton.Size = new System.Drawing.Size(59, 17);
            this.FemaleRadioButton.TabIndex = 4;
            this.FemaleRadioButton.TabStop = true;
            this.FemaleRadioButton.Text = "Female";
            this.FemaleRadioButton.UseVisualStyleBackColor = true;
            // 
            // DayOfBirthComboBox
            // 
            this.DayOfBirthComboBox.FormattingEnabled = true;
            this.DayOfBirthComboBox.Location = new System.Drawing.Point(183, 289);
            this.DayOfBirthComboBox.Name = "DayOfBirthComboBox";
            this.DayOfBirthComboBox.Size = new System.Drawing.Size(190, 21);
            this.DayOfBirthComboBox.TabIndex = 5;
            // 
            // MonthOfBirthComboBox
            // 
            this.MonthOfBirthComboBox.FormattingEnabled = true;
            this.MonthOfBirthComboBox.Location = new System.Drawing.Point(183, 243);
            this.MonthOfBirthComboBox.Name = "MonthOfBirthComboBox";
            this.MonthOfBirthComboBox.Size = new System.Drawing.Size(190, 21);
            this.MonthOfBirthComboBox.TabIndex = 6;
            // 
            // YearOfBirthComboBox
            // 
            this.YearOfBirthComboBox.FormattingEnabled = true;
            this.YearOfBirthComboBox.Location = new System.Drawing.Point(183, 198);
            this.YearOfBirthComboBox.Name = "YearOfBirthComboBox";
            this.YearOfBirthComboBox.Size = new System.Drawing.Size(190, 21);
            this.YearOfBirthComboBox.TabIndex = 7;
            // 
            // ShowButton
            // 
            this.ShowButton.BackColor = System.Drawing.Color.Crimson;
            this.ShowButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.ShowButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
            this.ShowButton.ForeColor = System.Drawing.Color.White;
            this.ShowButton.Location = new System.Drawing.Point(115, 336);
            this.ShowButton.Name = "ShowButton";
            this.ShowButton.Size = new System.Drawing.Size(190, 39);
            this.ShowButton.TabIndex = 8;
            this.ShowButton.Text = "Add";
            this.ShowButton.UseVisualStyleBackColor = false;
            this.ShowButton.Click += new System.EventHandler(this.ShowButton_Click);
            // 
            // FirstNameLabel
            // 
            this.FirstNameLabel.AutoSize = true;
            this.FirstNameLabel.Location = new System.Drawing.Point(74, 40);
            this.FirstNameLabel.Name = "FirstNameLabel";
            this.FirstNameLabel.Size = new System.Drawing.Size(54, 13);
            this.FirstNameLabel.TabIndex = 9;
            this.FirstNameLabel.Text = "FirsName:";
            // 
            // LastNameLabel
            // 
            this.LastNameLabel.AutoSize = true;
            this.LastNameLabel.Location = new System.Drawing.Point(74, 83);
            this.LastNameLabel.Name = "LastNameLabel";
            this.LastNameLabel.Size = new System.Drawing.Size(58, 13);
            this.LastNameLabel.TabIndex = 10;
            this.LastNameLabel.Text = "LastName:";
            // 
            // GenderLabel
            // 
            this.GenderLabel.AutoSize = true;
            this.GenderLabel.Location = new System.Drawing.Point(74, 165);
            this.GenderLabel.Name = "GenderLabel";
            this.GenderLabel.Size = new System.Drawing.Size(45, 13);
            this.GenderLabel.TabIndex = 12;
            this.GenderLabel.Text = "Gender:";
            // 
            // FacultyLabel
            // 
            this.FacultyLabel.AutoSize = true;
            this.FacultyLabel.Location = new System.Drawing.Point(74, 129);
            this.FacultyLabel.Name = "FacultyLabel";
            this.FacultyLabel.Size = new System.Drawing.Size(44, 13);
            this.FacultyLabel.TabIndex = 11;
            this.FacultyLabel.Text = "Faculty:";
            // 
            // MonthOfBirthLabel
            // 
            this.MonthOfBirthLabel.AutoSize = true;
            this.MonthOfBirthLabel.Location = new System.Drawing.Point(74, 243);
            this.MonthOfBirthLabel.Name = "MonthOfBirthLabel";
            this.MonthOfBirthLabel.Size = new System.Drawing.Size(72, 13);
            this.MonthOfBirthLabel.TabIndex = 14;
            this.MonthOfBirthLabel.Text = "Month of birth";
            // 
            // YearOfBirthLabel
            // 
            this.YearOfBirthLabel.AutoSize = true;
            this.YearOfBirthLabel.Location = new System.Drawing.Point(74, 198);
            this.YearOfBirthLabel.Name = "YearOfBirthLabel";
            this.YearOfBirthLabel.Size = new System.Drawing.Size(67, 13);
            this.YearOfBirthLabel.TabIndex = 13;
            this.YearOfBirthLabel.Text = "Year of birth:";
            // 
            // DayOfBirthLabel
            // 
            this.DayOfBirthLabel.AutoSize = true;
            this.DayOfBirthLabel.Location = new System.Drawing.Point(74, 289);
            this.DayOfBirthLabel.Name = "DayOfBirthLabel";
            this.DayOfBirthLabel.Size = new System.Drawing.Size(61, 13);
            this.DayOfBirthLabel.TabIndex = 15;
            this.DayOfBirthLabel.Text = "Day of birth";
            // 
            // frmStudentRegistration
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(427, 394);
            this.Controls.Add(this.DayOfBirthLabel);
            this.Controls.Add(this.MonthOfBirthLabel);
            this.Controls.Add(this.YearOfBirthLabel);
            this.Controls.Add(this.GenderLabel);
            this.Controls.Add(this.FacultyLabel);
            this.Controls.Add(this.LastNameLabel);
            this.Controls.Add(this.FirstNameLabel);
            this.Controls.Add(this.ShowButton);
            this.Controls.Add(this.YearOfBirthComboBox);
            this.Controls.Add(this.MonthOfBirthComboBox);
            this.Controls.Add(this.DayOfBirthComboBox);
            this.Controls.Add(this.FemaleRadioButton);
            this.Controls.Add(this.MaleRadioButton);
            this.Controls.Add(this.FacultyTextBox);
            this.Controls.Add(this.LastNameTextBox);
            this.Controls.Add(this.FirstNameTextBox);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Name = "frmStudentRegistration";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
            this.Text = "Form Student Registration";
            this.ResumeLayout(false);
            this.PerformLayout();


        }


        #endregion


        private System.Windows.Forms.TextBox FirstNameTextBox;
        private System.Windows.Forms.TextBox LastNameTextBox;
        private System.Windows.Forms.TextBox FacultyTextBox;
        private System.Windows.Forms.RadioButton MaleRadioButton;
        private System.Windows.Forms.RadioButton FemaleRadioButton;
        private System.Windows.Forms.ComboBox DayOfBirthComboBox;
        private System.Windows.Forms.ComboBox MonthOfBirthComboBox;
        private System.Windows.Forms.ComboBox YearOfBirthComboBox;
        private System.Windows.Forms.Button ShowButton;
        private System.Windows.Forms.Label FirstNameLabel;
        private System.Windows.Forms.Label LastNameLabel;
        private System.Windows.Forms.Label GenderLabel;
        private System.Windows.Forms.Label FacultyLabel;
        private System.Windows.Forms.Label MonthOfBirthLabel;
        private System.Windows.Forms.Label YearOfBirthLabel;
        private System.Windows.Forms.Label DayOfBirthLabel;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS