新建立一个C#窗体,他就有这些代码:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace WindowsApplication6
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null) 
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
// 
// Form1
// 
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main() 
{
Application.Run(new Form1());
} private void Form1_Load(object sender, System.EventArgs e)
{

}
}
}
这个中间的
protected override void Dispose( bool disposing 和InitializeComponent();以及private System.ComponentModel.Container components = null;到底是啥意思?

解决方案 »

  1.   

    >>protected override void Dispose( bool disposing 和InitializeComponent();
    这个函数是在窗体关闭时用来释放资源的。
    循环检查窗体中的所有对象,
    如果不是null    >>private System.ComponentModel.Container components = null;
    就释放这个对象的资源。
      

  2.   

    >>private System.ComponentModel.Container components = null;
    呵呵,经常看还真没了解过,佩服楼主细心
      

  3.   

    InitializeComponent()这方面里面给控件赋初值,
    事件处理程序注册。