每日随笔——c#窗口控件联系
自己设计并编写一个 Windows 应用程序,要求用到 TextBox、GroupBox、
RadioButton、CheckBox、ComboBox、ListBox 控件。将程序功能、界面布局和运行结果
的截图与事件代码写在实验报告中。
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 WinFormsApp2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); this.comboBox1.Items.Add("团员"); this.comboBox1.Items.Add("群众"); this.comboBox1.Items.Add("预备党员"); this.comboBox1.Items.Add("党员"); this.comboBox2.Items.Add("信息科学与技术学院"); this.comboBox2.Items.Add("土木学院"); this.comboBox2.Items.Add("经济管理学院"); this.comboBox2.Items.Add("电气学院"); this.comboBox2.Items.Add("文法学院"); } private void checkBox5_CheckedChanged(object sender, EventArgs e) { } private void textBox1_TextChanged(object sender, EventArgs e) { } private void textBox2_TextChanged(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { string msg = ""; msg = "姓名:" + textBox1.Text + "学号:" + textBox2.Text + "性别:"; if (radioButton1.Checked) { msg = msg + radioButton1.Text; } else if (radioButton2.Checked) { msg = radioButton2.Text; } msg = msg + "政治面貌" + this.comboBox1.SelectedItem.ToString(); msg = msg + "院系" + this.comboBox2.SelectedItem.ToString() + "爱好:"; if (checkBox1.Checked) { msg = msg + " " + checkBox1.Text; } if (checkBox2.Checked) { msg = msg + " " + checkBox2.Text; } if (checkBox3.Checked) { msg = msg + " " + checkBox3.Text; } if (checkBox4.Checked) { msg = msg + " " + checkBox4.Text; } MessageBox.Show(msg); } private void button2_Click(object sender, EventArgs e) { Application.Exit(); } private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { comboBox3.Items.Clear(); if (comboBox2.Text == "信息科学与技术学院") { comboBox3.Items.Add("信2105-1班"); comboBox3.Items.Add("信2105-3班"); } if (comboBox2.Text == "土木学院") { comboBox3.Items.Add("土2105-1班"); comboBox3.Items.Add("土2105-2班"); } if (comboBox2.Text == "文法学院") { comboBox3.Items.Add("文2105-1班"); comboBox3.Items.Add("文2105-2班"); } if (comboBox2.Text == "经济管理学院") { comboBox3.Items.Add("经2105-1班"); comboBox3.Items.Add("经2105-2班"); } if (comboBox2.Text == "电气学院") { comboBox3.Items.Add("电2105-1班"); comboBox3.Items.Add("电21055-2班"); } } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { } } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类