每日随笔——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)
        {

        }
    }
}

 

posted @ 2023-10-24 19:54  伽澄  阅读(30)  评论(0编辑  收藏  举报