获取特定类型的所有控件 [英] Get all controls of a specific type
本文介绍了获取特定类型的所有控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有多个pictureboxes,我需要加载的随机图像转换成它们在运行时。所以,我认为这将是不错的所有pictureboxes的集合,然后分配使用一个简单的循环影像给他们。不过,我应该怎么办呢?或者,也许是有这样的问题,任何其他更好的解决办法?
I have multiple pictureboxes and I need to load random images into them during runtime. So I thought it would be nice to have a collection of all pictureboxes and then assign images to them using a simple loop. But how should I do it? Or maybe are there any other better solutions to such problem?
推荐答案
使用LINQ一点的:
foreach(var pb in this.Controls.OfType<PictureBox>())
{
//do stuff
}
不过,这将只需要在主容器护理PictureBoxes的。
However, this will only take care of PictureBoxes in the main container.
这篇关于获取特定类型的所有控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文