C#设计并编写一个 Windows 应用程序,要求用到 TextBox、GroupBox、RadioButton、CheckBox、ComboBox、ListBox 控件

此篇博客详细介绍了使用C#编写的Windows Form应用程序,展示了如何验证用户输入的姓名、性别、课程选择和爱好,同时强调了必填字段的检查。通过实例演示了控件交互和条件判断在用户界面中的应用。
namespace sy3_2_20193947
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "") { label7.Text = textBox1.Text; }                                  //姓名

            else MessageBox.Show("姓名不能为空!\n");
            if (radioButton1.Checked) { label2.Text = radioButton1.Text; } //男

            if (radioButton2.Checked) { label2.Text = radioButton2.Text; } //女
            if (checkBox1.CheckState == CheckState.Checked) { label10.Text = checkBox1.Text; }

            else label10.Text = "";

            if (checkBox2.CheckState == CheckState.Checked) { label16.Text = checkBox2.Text; }

            else label16.Text = "";

            if (checkBox3.CheckState == CheckState.Checked) { label17.Text = checkBox3.Text; }

            else label17.Text = "";

            if (checkBox3.CheckState == CheckState.Checked) { label18.Text = checkBox4.Text; }

            else label18.Text = "";
            if (checkBox1.CheckState == CheckState.Unchecked && checkBox2.CheckState == CheckState.Unchecked && checkBox3.CheckState == CheckState.Unchecked && checkBox4.CheckState == CheckState.Unchecked) { MessageBox.Show("请选择所学课程\n"); }
            if (comboBox1.Text != "") { label13.Text = comboBox1.Text; }//班级

            else MessageBox.Show("班级不能为空!\n");
            if (listBox1.Text != "") { label15.Text = listBox1.Text; } //爱好

            else MessageBox.Show("请选择爱好!\n");

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

这辈子秃头是不可能的

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值