
在button1_Click事件中,创建label,代码:
Label lb1 = new Label()
lb1.Name = "panel"+j
lb1.BackColor = Color.Transparent
lb1.BorderStyle = BorderStyle.FixedSingle
Panel1.Controls.Add(lb1)
为这些label增加Click事件
Label lb1 = new Label()
lb1.Name = "panel"+j
lb1.BackColor = Color.Transparent
你只是移除了!!没有释放啊!!while (panel1.Controls.Count >0)
{
panel1.Invoke((Action)delegate
{
Control C=panel1.Controls[0])
panel1.Controls.Remove(C)
C.Dispose()
})
}
private void button1_Click(object sender, EventArgs e){
Clear(this)
//label1.Text = i.ToString()
}
private void Clear(Control ctrl)
{
foreach (Control c in Controls)
{
if (c is Button)
{
c.Dispose()
//i++
Clear(c)
}
}
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)