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;
            }
        }

 
    HK
 
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号