public void addPic() { picList = new List<PictureBox>(); PictureBox p1 = new PictureBox(); p1.Load("C://Documents and Settings//Administrator//桌面//11.png"); p1.Name = "11"; picList.Add(p1); } public void drawPic() { PictureBox pic = picList.Find(delegate(PictureBox s) { return s.Name == "11"; } ); if (pic == null) { MessageBox.Show("没找到"); return; } pic.Location = new System.Drawing.Point(144, 144); this.Controls.Add(pic); }
用于测试是否能够使用 List<T> 目前已经明白了如何添加和遍历寻找一个元素 使用find方法。
需要进一步了解 findall 方法。参考的是MSDN和一些网上的文章
http://msdn.microsoft.com/zh-cn/library/x0b5b5bc.aspx
2011-02-11