如何删除动态创建的控件? [英] How to remove dynamic created controls?

查看:68
本文介绍了如何删除动态创建的控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨需要一些帮助..

我的表单包含1个按钮和1个picbox。

i通过调用我声明标签的函数在页面加载事件上创建动态标签控件创建代码。

我希望当我点击按钮时我想删除所有标签。

当我在我创建的函数上运行此代码时标签显示没有错误这个.Controls.Remove(标签);

但是当我在按钮点击事件上运行此代码时,它显示此错误当前上下文中不存在名称'标签'任何人都可以显示我尽快修复它。

hi need some assistance..
My form contains 1 button and 1 picbox.
i created dynamic labels controls on page load event by calling a function where i declare labels creating code.
I want when i click on the button i want to remove all labels.
when i run this code on the function i created label show no error "this.Controls.Remove(labels);"
But when i run this code on button click event it show this error "The name 'labels' does not exist in the current context" can any one please show me way to fix it ASAP.

推荐答案

可能是因为this关键字,在按钮点击事件处理程序中this指的是按钮对象,当你在页面加载事件中添加标签时this指的是页面对象。



这可能对你有所帮助:

https://msdn.microsoft.com/en-us/library/aa 984275(v = vs.71).aspx [ ^ ]
It might be because of the "this" keyword, inside the button click event handler "this" refers to the button object, where as when you added the lables in page load event "this" refers the page object.

this might help you :
https://msdn.microsoft.com/en-us/library/aa984275(v=vs.71).aspx[^]


您能否提供更详细的代码。
Can you provide the code for more clarification.


这篇关于如何删除动态创建的控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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