问题描述
找不到看似简单的问题的答案.我需要遍历窗体上的控件,并且如果控件是CheckBox并被选中,则应完成某些操作.像这样
Can't find the answer to a seemingly easy question. I need to iterate through the controls on a form, and if a control is a CheckBox, and is checked, certain things should be done. Something like this
foreach (Control c in this.Controls)
{
if (c is CheckBox)
{
if (c.IsChecked == true)
// do something
}
}
但是我无法到达IsChecked属性.
But I can't reach the IsChecked property.
错误是'System.Windows.Forms.Control'不包含'IsChecked'的定义,并且找不到扩展方法'IsChecked'接受类型为'System.Windows.Forms.Control'的第一个参数(您是否缺少using指令或程序集引用?)
The error is 'System.Windows.Forms.Control' does not contain a definition for 'IsChecked' and no extension method 'IsChecked' accepting a first argument of type 'System.Windows.Forms.Control' could be found (are you missing a using directive or an assembly reference?)
我如何到达此酒店?提前非常感谢!
How can I reach this property? Thanks a lot in advance!
编辑
好吧,回答所有-我尝试了强制转换,但这是行不通的.
Okay, to answer all - I tried casting, it doesn't work.
推荐答案
您已经关闭.您要查找的属性是已选中
You're close. The property you're looking for is Checked
foreach (Control c in this.Controls) {
if (c is CheckBox) {
if (((CheckBox)c).Checked == true)
// do something
}
}
这篇关于如何获取WinForm控件的IsChecked属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!