我想在我的flowLayoutPanel为空时出现错误标签,但我不知道如何检查flowLayoutPanel是否为空。这是我目前的代码:
private void flowLayoutPanel1_ControlRemoved(object sender, ControlEventArgs e)
{
if (flowLayoutPanel1.Controls == null)
{
customtoolwarning.Visible = true;
}
else
{
customtoolwarning.Visible = false;
}
}
请帮助,
由于
答案 0 :(得分:4)
private void flowLayoutPanel1_ControlRemoved(object sender, ControlEventArgs e)
{
if (flowLayoutPanel1.Controls.Count > 0)
{
customtoolwarning.Visible = true;
}
else
{
customtoolwarning.Visible = false;
}
}
答案 1 :(得分:2)
您遇到的问题是,您正在检查Controls
null
以确定它是否为空。 Controls
属性永远不会是null
,而是非空,并且在空时为0。例如
if (flowLayoutPanel1.Controls.Count == 0) {
// It's empty
}
答案 2 :(得分:0)
lblNoContacts.Visible = (flowLayoutPanel.Controls.Count == 0) ? true : false;