ITPub博客

首页 > IT职业 > IT职场 > C#里面多选框CheckBox的属性和事件

C#里面多选框CheckBox的属性和事件

IT职场 作者:adder 时间:2021-09-09 09:51:13 0 删除 编辑

在C#里面,多选框组件是:CheckBox。跟单选框一样,也是比较常用的一个组件。

多选框主要的属性是:Name、Text、Checked。

Name属性表示这个组件的名称。Text属性表示这个组件的标题。Checked表示这个组件是否已经选中。

主要的事件就是CheckedChanged事件。

比如:选择一下个人的兴趣和爱好的多选。相关效果和代码如下所示:

void CheckBox1CheckedChanged(object sender, EventArgs e)
        {
            if(checkBox1.Checked)
            {
                textBox1.AppendText(checkBox1.Text+"n");
            }
        }
        void CheckBox2CheckedChanged(object sender, EventArgs e)
        {
            if(checkBox1.Checked)
            {
                textBox1.AppendText(checkBox2.Text+"n");
            }
        }
        void CheckBox3CheckedChanged(object sender, EventArgs e)
        {
            if(checkBox3.Checked)
            {
                textBox1.AppendText(checkBox3.Text+"n");
            }
        }
        void CheckBox4CheckedChanged(object sender, EventArgs e)
        {
            if(checkBox4.Checked)
            {
                textBox1.AppendText(checkBox4.Text+"n");
            }
        }

图片描述

原文链接:http://www.apkbus.com/blog-56257-75902.html

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1595/viewspace-2813424/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    110
  • 访问量
    725