C#-GroupBox包含控件,如何获取这些控件的名称


您可以使用 Enumerable.OfType在GroupBox中查找和投射您的RadioButtons:

var radioButtons = groupBox1.Controls.OfType<RadioButton>();
foreach (RadioButton rb in radioButtons) { bool state = rb.Checked; string name = rb.Name; }





模拟PLC读取:

private void btnAgree_Click(object sender, EventArgs e)
{
int readValue = int.Parse(txtValue.Text);
foreach (Button item in groupBox1.Controls.OfType<Button>())
{
bool status;
if (item.Tag==null)
{
continue;
}
int index = int.Parse(item.Tag.ToString());
status = (readValue & (1 << index)) != 0;
item.BackColor = status ? Color.Green : Color.Gray;
}
}

 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM