添加/删除了相同的名称控件 [英] Adding / removing controls with same reference name

查看:160
本文介绍了添加/删除了相同的名称控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我后,其他面板一个在当用户点击一个按钮添加控件。
中的控制是逐一显示面板上之后。当面板充满例如十,
添加下一个控件,以取代添加的第一个控制,但首先我需要删除的第一个控制....问题是,正在创建的所有控件都具有相同的参考例如PIC,现在当我使用panel1.Controls.Remove(PIC),它没有指定在第一位置的控制需要删除!

I am adding controls on a panel one after the other when the user clicks on a button. The controls are displayed one after the other on the panel. When the panel is full e.g. ten, the next control added has to replace the first control that was added, but first I need to remove the first control.... the problem is that all the controls that are being created have the same reference e.g. "pic", now when I use panel1.Controls.Remove(pic) it does not specify that the control at the first position needs to be removed!!

int index = 0;  

if (util.GetSize() != 10)
{
    ms.Controls.Add(musNote);
}
else
{   
    ms.Controls.Add(musNote); //this to replace first musNote added... but before I need to remove the musNote that in that position already (problem all of the are musNote!!
    index++;
    if (index == 10)
    {
        index = 0;
    }
}
musNote.ShowNote();

以上是不是整个代码,但应该足以解决这个问题。如果任何信息是必要的。请让我NP。韩国社交协会提前的帮助。

The above is not the entire code but should be enough to tackle the problem.. if any info. is needed please ask me np. Tks in advance for the help.

推荐答案

<击>如果你只是想删除第一个孩子使用的 RemoveAt移除

myPanel.Controls.RemoveAt(0);

不要使用上面的代码,它会在处理,使用电池作为在意见建议@Hans

Don't use above code, it will leak in Handle, use Dispose as @Hans suggested in comments

myPanel.Controls[0].Dispose();//This takes care of destroying the window

这篇关于添加/删除了相同的名称控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆