加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 01:54:52 所属栏目:百科 来源:网络整理
导读:我已经阅读(在 using Statement (C# Reference))应该使用using语句来释放使用非托管资源的托管类型(如文件和字体)使用的资源.所以开始将它与MySql类和相关的东西一起使用,但是如果你看一下Windows.Forms.Form类的一个对象,你会看到一个Dispose方法,这意味着
我已经阅读(在 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读