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

标签 c# winforms using-statement

我读过(在 using Statement (C# Reference) 上)using 语句应该用于释放使用非托管资源的托管类型(如文件和字体)所使用的资源。所以开始将它与 MySql 类和相关的东西一起使用,但是如果你看一下 Windows.Forms.Form 类的对象,你会看到一个 Dispose 方法,这意味着这个类实现了 IDisposable 所以,我应该使用 像下面的情况一样对 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

关于c# - 我应该使用 using 语句来创建 Windows.Forms.Form 对象吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16610142/

相关文章:

c# - 如何避免在C#、ASP.NET中更改单元格背景后删除Excel工作表的网格线颜色(默认浅灰色)?

c# - 使用 rijndael 加密

c# - 在Visual Studio中运行时,代码运行良好,但.Exe挂起该代码

c# - 无法加载文件或程序集“System.Data.SQLite.SEE.License,版本=1.0.117.0”

c# - 在单个 'IDisposable' 语句中嵌套 'using'

vb.net - SqlCommand(使用语句/处置问题)

c# - 如何在 C# 中获取队列中打印作业的文件路径

c# - 如何检查Dictionary是否已具有键“x”?

c# - 在数据库中发送带有附件路径的批量电子邮件

c# - 我应该将 C# 的 using 语句用于哪些类?