c# – 在Winforms上处理控件
发布时间:2020-12-15 04:13:54 所属栏目:百科 来源:网络整理
导读:为什么Visual Studio将此代码添加到Class.Designer.cs分部类中. 任何人都能告诉我这个组件变量什么时候会得到一些价值?这里的模式是什么? private System.ComponentModel.IContainer components = null; /// summary /// Clean up any resources being use
为什么Visual Studio将此代码添加到Class.Designer.cs分部类中.
任何人都能告诉我这个组件变量什么时候会得到一些价值?这里的模式是什么? private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise,false.</param> protected override void Dispose(bool disposing) { if(disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } 解决方法
私有字段组件用于跟踪表单上的一次性组件.尝试拖动Timer组件,您应该在设计器生成的代码中看到类似的内容:
this.components = new System.ComponentModel.Container(); this.timer1 = new System.Windows.Forms.Timer(this.components); Dispose(bool)方法中显示的模式通常称为the disposable pattern.基本上,该模式确保将处置所有跟踪的组件,即使您从未明确调用Dispose方法,在这种情况下基类您的表单将在其终结器中调用Dispose方法(在垃圾回收期间). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |