Unload 控件数组的问题
用Load方法加载了很多控件:Label,TextBox,RichTextBox,DataGrid
结果用Unload方法去掉这些控件的时候报错:
unable to unload within this context
同样的程序在另外一个窗体可以运行,搜索了一下,有这种解释:
In some situations you are not allowed to unload a form or a control on a form. This error has the following causes and solutions:
There is an Unload statement in the Paint event for the form or for a control on the form that has the Paint event.
Remove the Unload statement from the Paint event.
There is an Unload statement in the Change, Click, or DropDown events of a ComboBox.
Remove the Unload statement from the event.
There is an Unload statement in the Scroll event of an HScrollBar or VScrollBar control.
Remove the Unload statement from the event.
There is an Unload statement in the Resize event of a Data, Form, MDIForm, or PictureBox control.
Remove the Unload statement from the event.
There is an Unload statement in the Resize event of an MDIForm that is trying to unload an MDI child form.
Remove the Unload statement from the event.
There is an Unload statement in the RePosition or Validate event of a Data control.
Remove the Unload statement from the event.
There is an Unload statement in the ObjectMove event of an OLE Container control.
Remove the Unload statement from the event.
但问题是我程序里面没有上面任何一种情况,为什么呢?
[解决办法]
......
你调用一下UNLOAD方法,然后调用被UNLOAD的窗体内某控件事件或者属性什么的,看看出错没..出错了就是你卸载成功了..管他符合不符合干什么,,,,教条
[解决办法]
unload之前,确保程序和进程对窗体或者控件的调用已经结束。确保load进来的控件都存在。如果unload已经卸载的控件,程序会出错。