C# Winform项目,如何在Panel控件中判断已经存在的对象

C# Winform项目,如何在Panel控件中判断已经存在的对象

问题描述:

在C# Winform项目,有一个form窗体,在form窗体中包函一个Panel控件,一个PictureBox控件以及一个Label控件。
目前想实现点击PictureBox控件或Label控件,将PictureBox控件或Label控件添加到Panel控件中。

如何在PictureBox控件或Label控件点击事件中,实现判断如果Panel控件已经包函了PictureBox控件,就无法将Label控件添加到Panel控件中,
反之,如果Panel控件已经包函了Label控件,就无法将PictureBox控件添加到Panel控件中。

请问,如何判断Panel控件中是否包函PictureBox控件或Label控件对象。
请各位帮忙提供下相关的参考资料,谢谢!

foreach(control var in this.panel.controls)
{
if(var is Label)
{
//表明已经包含了label对象
//picturebox对象可以用同样的方法判断
}
}

 if (Panel.Controls.OfType<Label>().Any(x => x == label1))
....

那PictureBox控件或buttton按钮,应该如何判断呢?