基于C#編寫計算機選課程序
一、引言
在這篇文章中,我將介紹如何開發(fā)一個簡單的計算機選課程序。這個程序?qū)⒃试S學(xué)生根據(jù)自己的需求選擇不同等級的課程,并即時顯示他們的選課情況。我們將使用C#語言和Windows Forms來構(gòu)建這個應(yīng)用程序。
二、程序概述
我們的選課程序?qū)齻€等級的課程:基礎(chǔ)課、語言課和應(yīng)用課?;A(chǔ)課和語言課為限選課程,而應(yīng)用課為任選課程。學(xué)生每選一門課程,選課情況將立即顯示在多行文本框中。
三、 界面設(shè)計
程序界面將包含三個部分:基礎(chǔ)課選擇、語言課選擇和應(yīng)用課選擇?;A(chǔ)課和語言課將使用單選按鈕(RadioButton)來選擇,而應(yīng)用課將使用復(fù)選框(CheckBox)來選擇。
四、代碼實現(xiàn)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace _6_1_ { public partial class Form1 : Form { public Form1() { InitializeComponent(); } string first = ""; string second = ""; string third = ""; // 檢查基礎(chǔ)課選擇 private void checkFirst() { if (radioButton1.Checked) first = radioButton1.Text; else if (radioButton2.Checked) first = radioButton2.Text; } // 檢查語言課選擇 private void checkSecond() { if (radioButton4.Checked) second = radioButton4.Text; else if (radioButton3.Checked) second = radioButton3.Text; else if (radioButton6.Checked) second = radioButton6.Text; else if (radioButton5.Checked) second = radioButton5.Text; else if (radioButton7.Checked) second = radioButton7.Text; } // 檢查應(yīng)用課選擇 private void checkThird() { 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 + " "; } // 顯示選課結(jié)果 private void showMsg() { textBox1.Text = "您的選課結(jié)果如下:\r\n"; if (!first.Equals("")) textBox1.Text += "基礎(chǔ):" + first + "\r\n"; if (!second.Equals("")) textBox1.Text += "語言:" + second + "\r\n"; if (!third.Equals("")) textBox1.Text += "應(yīng)用:" + third + "\r\n"; } // 事件處理 private void radioButton4_CheckedChanged(object sender, EventArgs e) { checkFirst(); showMsg(); } private void Form1_Load(object sender, EventArgs e) { checkSecond(); showMsg(); } private void checkBox4_CheckedChanged(object sender, EventArgs e) { checkThird(); showMsg(); } } }
五、為每一個選項添加事件
每一個選項都要選擇右邊菜單欄中的check事件
六、事件處理
radioButton4_CheckedChanged:當語言課的單選按鈕狀態(tài)改變時,調(diào)用checkFirst和showMsg方法來更新選課結(jié)果。
checkBox4_CheckedChanged:當應(yīng)用課的復(fù)選框狀態(tài)改變時,調(diào)用checkThird和showMsg方法來更新選課結(jié)果。
七、完成展示
到此這篇關(guān)于基于C#編寫計算機選課程序的文章就介紹到這了,更多相關(guān)C#計算機選課程序內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
WPF實現(xiàn)雷達圖(仿英雄聯(lián)盟)的示例代碼
這篇文章主要介紹了如何利用WPF實現(xiàn)雷達圖(仿英雄聯(lián)盟)的繪制,文中的示例代碼講解詳細,對我們學(xué)習或工作有一定幫助,需要的可以參考一下2022-07-07C# IDE VS2005中的Hosting Process (vshost.exe)作用介紹
這篇文章主要介紹了C# IDE VS2005中的Hosting Process (vshost.exe)作用介紹,vshost.exe是一個宿主進程,主要用來提高調(diào)試效率,需要的朋友可以參考下2015-01-01