c# winfrom。有4个 checkBox控件,如何判断只要选中,就把选中的checkbox的内容放一起显示出来?
6个回答
展开全部
this.checkBox1.CheckedChanged += new EventHandler(CheckedChanged);
this.checkBox2.CheckedChanged += new EventHandler(CheckedChanged);
this.checkBox3.CheckedChanged += new EventHandler(CheckedChanged);
this.checkBox4.CheckedChanged += new EventHandler(CheckedChanged);
//选中的CheckBox的文本
private string strCheckBoxText = null;
void CheckedChanged(object sender, EventArgs e)
{
strCheckBoxText = string.Empty;
if (checkBox1.Checked)
{
strCheckBoxText = checkBox1.Text + ",";
}
if (checkBox2.Checked)
{
strCheckBoxText += checkBox2.Text + ",";
}
if (checkBox3.Checked)
{
strCheckBoxText += checkBox3.Text + ",";
}
if (checkBox4.Checked)
{
strCheckBoxText += checkBox4.Text;
}
if (!string.IsNullOrEmpty(strCheckBoxText))
{
strCheckBoxText = strCheckBoxText.TrimEnd(',');
}
}
this.checkBox2.CheckedChanged += new EventHandler(CheckedChanged);
this.checkBox3.CheckedChanged += new EventHandler(CheckedChanged);
this.checkBox4.CheckedChanged += new EventHandler(CheckedChanged);
//选中的CheckBox的文本
private string strCheckBoxText = null;
void CheckedChanged(object sender, EventArgs e)
{
strCheckBoxText = string.Empty;
if (checkBox1.Checked)
{
strCheckBoxText = checkBox1.Text + ",";
}
if (checkBox2.Checked)
{
strCheckBoxText += checkBox2.Text + ",";
}
if (checkBox3.Checked)
{
strCheckBoxText += checkBox3.Text + ",";
}
if (checkBox4.Checked)
{
strCheckBoxText += checkBox4.Text;
}
if (!string.IsNullOrEmpty(strCheckBoxText))
{
strCheckBoxText = strCheckBoxText.TrimEnd(',');
}
}
追问
谢谢耐心回答。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询