这是我刚刚开始练习C#中的多选checkbox控件编得程序,但是编译不过去
Label.Text = "你喜欢的是";
            foreach (Control  c in this.Controls)
            { 
                if (c!=null )
                {
                   if (c is CheckBox )
                   {
                   
                       CheckBox check=(CheckBox)c;
                    if (check.Checked)
                     {
                 
                        Label.Text+=checked.Text;
                
                      }
                    }
                }
            
            
            }
  

解决方案 »

  1.   

    Label.Text+=checked.Text;
    checked.Text  改成 check.Text
      

  2.   

    foreach (Control c in this.Controls)
      {  
      if (c is CheckBox )
      {
      CheckBox check=c as CheckBox;
      if(check!=null && check.Checked)
      {
      Label.Text+=check.Text+","; 
      }
      }
      }
      }
      

  3.   

    checked多了个ed,把ed去掉就可以了
    低价源码出售了,全是自己开发的代码,希望和大家一起交流,集百家之所长,希望能对大家有所帮助。
    网店地址:http://shop36675020.taobao.com
      

  4.   

    四楼正解 代码也可以这样写foreach (Control c in this.Controls)

      checkBox check = c as CheckBox 
      if (check != null && check.checked)
      {
          Label.Text+=check.Text+","; 
      }
    }
      

  5.   

      private void button1_Click(object sender, EventArgs e)
            {
               
              label1.Text = "你喜欢的是";
                foreach (Control c in this.Controls)//Controls
                {
                    if (c != null)
                    {
                        if (c is CheckBox)
                        {
                            CheckBox check = (CheckBox)c;
                            if (check.Checked == true)
                            {
                                label1.Text += check.Text;
                            }
                        }
                    }
                }
            }