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