微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 我应该使用using语句来创建Windows.Forms.Form对象吗?

我已经阅读(在 using Statement (C# Reference))应该使用using语句来释放使用非托管资源的托管类型(如文件和字体)使用的资源.所以开始将它与MysqL类和相关的东西一起使用,但是如果你看一下Windows.Forms.Form类的一个对象,你会看到一个dispose方法,这意味着这个类实现了Idisposable所以,我应该使用using语句对于Windows.Forms.Form对象,如下面的情况?

private void aboutToolStripMenuItem_Click(object sender,EventArgs e)
{
    using (AboutBoxProjeto about = new AboutBoxProjeto())
    {
        about.ShowDialog();
    }
}

解决方法

http://dotnetfacts.blogspot.com/2008/03/things-you-must-dispose.html开始:

In .NET,a dialog form is a form opened by calling the ShowDialog() method. Unlike modeless forms,the Close method is not called by the .NET Framework when the user clicks the close form button of a dialog Box or sets the value of the DialogResult property. Instead the form is hidden and can be shown again without creating a new instance of the dialog Box. Because a form displayed as a dialog Box is not closed,you must call the dispose() method of the form when the form is no longer needed by your application

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐