简体   繁体   English

如何轻松处理表格

[英]How to easily dispose forms

I'm wondering if there is someway I can automatically dispose winforms. 我想知道是否可以自动处置Winform。 My project is massive, with about 6 forms. 我的项目规模巨大,大约有6种形式。 I've had all sorts of errors, and they all lead to me not disposing GDI+ objects. 我遇到了各种各样的错误,所有这些错误都导致我不处理GDI +对象。 I've added a Dispose() line to all my formclosing events. 我已经向所有关闭窗体的事件添加了Dispose()行。 If there is no way to automatically dispose forms, is there any other way to stop these errors. 如果没有自动处理表格的方法,那么还有其他方法可以阻止这些错误。

All the errors I've had so far are 到目前为止,我所有的错误都是

  • Parameter not valid 参数无效
  • Stack overflow 堆栈溢出
  • Unable to create window handle 无法创建窗口句柄

There are probably more that I don't remember, please end this month long nightmare. 可能还有更多我不记得的事情,请结束本月漫长的噩梦。

EDIT 编辑

The latest error appears in a child form of Form1 in the child's designer. 最新的错误在孩子的设计器中以Form1的孩子形式出现。 On the first line, it throws 在第一行,它抛出

Error creating window handle 创建窗口句柄时出错

The stack trace is just 堆栈跟踪只是

System.Windows.Forms.NativeWindow.Create(Parameters tp)

Generally closing a form by clicking the X button should dispose the form object along with all it's child object since form is the parent container and so when it's dispose is called it will in turn call all it's child dispose. 通常,通过单击X按钮关闭表单应该将表单对象连同它的所有子对象一起处置,因为表单是父容器,因此,在调用dispose时,它将依次调用其所有子处置。

But depends on what you are doing exactly in your form closing event. 但是取决于您在表单关闭事件中到底在做什么。 I have seen many people do this.hide() on FormClosing event. 我已经看到很多人在FormClosing事件上执行this.hide() That means, you are not actually closing/disposing the forms. 这意味着您实际上并没有关闭/处置表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM