本文介绍了只有最后动态创建的图片框才可访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在创建一个 WinForm 应用程序,其中我有 TabControl1 并且在运行时创建 TabPage 和 PictureBox 。 按钮点击,我制作新标签页和 PictureBox 并将它们添加到 TabControl1 。 现在,我可以更改最后创建的 PictureBox 的图像。 当我尝试更改任何 PictureBox ,除了最后一个,我无法做到这一点 这是代码示例。 button1 创建新的 TabPage 和 PictureBox 。 private void button1_Click( object sender,EventArgs e) { TabPage tpgallery = new TabPage(); tpgallery.Name = tpgallery; tpgallery.Text = 图库; tabControl1.TabPages.Add(tpgallery); picturebox1 = new PictureBox(); picturebox1.Name = picturebox1name; picturebox1.Image = WindowsFormsApplication7.Properties.Resources.logo1; tpgallery.Controls.Add(picturebox1); } button2 更改 PictureBox 。 private void button2_Click( object sender,EventArgs e) { picturebox1.Image = WindowsFormsApplication7.Properties.Resources.logo2; } 更正了格式和语法问题。 [/ edit] 解决方案 I am creating a WinForm application, in which I have a TabControl1 and at run time created TabPage and PictureBox.On a Button Click, I make new tab page and PictureBox and add them to the TabControl1.Now, I can change image of only last created PictureBox.and when I try to change the image of any PictureBox, except the last one, I am not able to do thatThis is the code example.button1 creates new TabPage and PictureBox.private void button1_Click(object sender, EventArgs e){ TabPage tpgallery = new TabPage(); tpgallery.Name = "tpgallery"; tpgallery.Text = " Gallery "; tabControl1.TabPages.Add(tpgallery); picturebox1 = new PictureBox(); picturebox1.Name = "picturebox1name"; picturebox1.Image = WindowsFormsApplication7.Properties.Resources.logo1; tpgallery.Controls.Add(picturebox1); }button2 changes image of PictureBox.private void button2_Click(object sender, EventArgs e){ picturebox1.Image = WindowsFormsApplication7.Properties.Resources.logo2;}[Edit member="Tadit"]Corrected formatting and grammatical issues.[/Edit] 解决方案 这篇关于只有最后动态创建的图片框才可访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-15 20:19