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

相关文章

目录简介使用JS互操作使用ClipLazor库创建项目使用方法简单测...
目录简介快速入门安装 NuGet 包实体类User数据库类DbFactory...
本文实现一个简单的配置类,原理比较简单,适用于一些小型项...
C#中Description特性主要用于枚举和属性,方法比较简单,记录...
[TOC] # 原理简介 本文参考[C#/WPF/WinForm/程序实现软件开机...
目录简介获取 HTML 文档解析 HTML 文档测试补充:使用 CSS 选...