C#學生選課程式

不務正業的藝術生發表於2020-12-21

C#學生選課程式


namespace 課程選課
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //定義三個變數 first,second,third
        string first = "";
        string second = "";
        string third = "";
        

        private void First()//第一門課的方法
        {
            if (radioButton1.Checked)
                first = radioButton1.Text;
            else
               if (radioButton2.Checked)
                first = radioButton2.Text;
        }

        private void Second()//第二門課的方法
        {
            if (radioButton3.Checked)
                second = radioButton3.Text;
            if (radioButton4.Checked)
                second = radioButton4.Text;
            if (radioButton5.Checked)
                second = radioButton5.Text;
            if (radioButton6.Checked)
                second = radioButton6.Text;
            if (radioButton7.Checked)
                second = radioButton7.Text;
        }

        private void Third()//第三門課的方法
        {
            third = "";
            if (checkBox1.Checked)
                third += " " + checkBox1.Text + " ";
            if (checkBox2.Checked)
                third += " " + checkBox2.Text + " ";
            if (checkBox3.Checked)
                third += " " + checkBox3.Text + " ";
            if (checkBox4.Checked)
                third += " " + checkBox4.Text + " ";
            if (checkBox5.Checked)
                third += " " + checkBox5.Text + " ";
        }

        private void showMsg()//顯示結果的方法
        {
            textBox3.Text = "您的選課結果如下:\r\n";//"\r"回車的意思,"\n"換行的意思
            if (!first.Equals(""))
                textBox3.Text += "基礎:" + first + "\r\n";
            if (!second.Equals(""))
                textBox3.Text += "語言:" + second + "\r\n";
            if (!third.Equals(""))
                textBox3.Text += "應用:" + third;
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            First();
            showMsg();
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
           Second();
            showMsg();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            Third();
            showMsg();
        }
    }
}

在這裡插入圖片描述
原始碼在我的主頁有,可以去下載

相關文章