且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

嗨,大家好我在C#中创建动态控件,我遇到了删除功能的问题。

更新时间:2023-11-04 22:47:46

如果你想要删除某些东西,你必须采取相反的方式而不是创建。

在你的情况下:

- 从Button中删除处理程序(委托)(btnRe)

- 从控件集合中删除并处理控件tc

- 从tr中移除tc



如果你这样做它会起作用。

用于实现这样的代码我更喜欢创建一个方法CreateControls和另一个方法RemoveControls。这样会更清楚。
If you want to remove something you have to do it the other way round than creating.
In your case :
- remove the handler (delegate) from the Button (btnRe)
- remove and dispose the controls out of the controls-collection from tc
- remove tc from tr

If you do it like this it will work.
For realizing such code I would prefer to create a method "CreateControls" and another method "RemoveControls". That would be clearer arranged.