1 回答

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超5個(gè)贊
試試這個(gè):
對(duì)于Windows Forms:
bool found = false;
foreach (Control c in this.Controls)
{
if (c is Label && c.Text.Contains("abc"))
{
found = true;
break;
}
}
button1.Enabled = !found;
對(duì)于WPF:
bool found = false;
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(this.Content as DependencyObject); i++)
{
var v = VisualTreeHelper.GetChild(this.Content as DependencyObject, i);
if (v is Label && (v as Label).Content.ToString().Contains("abc"))
{
found = true;
break;
}
}
button.IsEnabled = !found;
- 1 回答
- 0 關(guān)注
- 180 瀏覽
添加回答
舉報(bào)