复选框选择变化(可以演化成简单的字符串拼接)

        //显示选中的文字
private void showText(string title)
{
//定义空字符串
string str = string.Empty;
//以下确认该字符串的值
if (checkBox1.Checked && !checkBox2.Checked)
str = checkBox1.Text;
if (checkBox2.Checked && !checkBox1.Checked)
str = checkBox2.Text;
if (checkBox1.Checked && checkBox2.Checked)
str = checkBox1.Text + checkBox2.Text;
//赋值给文本
label1.Text = title + str;
}

//复选框1选择变化事件
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
showText("你的爱好是:");

}

//复选框2选择变化事件
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
showText("你的爱好是:");
}


 

code in my life.
原文地址:https://www.cnblogs.com/ghypnus/p/2415151.html