代码,为了看得全面,相关代码都贴出来了。
private void InitializeComponent()
{
         this.components = new System.ComponentModel.Container();
         System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(LineCounter));
         this.txtFile = new System.Windows.Forms.TextBox();
         this.btnBrowse = new System.Windows.Forms.Button();
         this.btnExit = new System.Windows.Forms.Button();
         this.btnRun = new System.Windows.Forms.Button();
         this.chkComment = new System.Windows.Forms.CheckBox();
         this.chkBlank = new System.Windows.Forms.CheckBox();
         this.panel1 = new System.Windows.Forms.Panel();
         this.chkCobol = new System.Windows.Forms.CheckBox();
         this.chkAsp = new System.Windows.Forms.CheckBox();
         this.chkC = new System.Windows.Forms.CheckBox();
         this.chkCpp = new System.Windows.Forms.CheckBox();
         this.chkCs = new System.Windows.Forms.CheckBox();
         this.chkJava = new System.Windows.Forms.CheckBox();
         this.label1 = new System.Windows.Forms.Label();
         this.linkLabel1 = new System.Windows.Forms.LinkLabel();
         this.linkLabel2 = new System.Windows.Forms.LinkLabel();
         this.tp = new System.Windows.Forms.ToolTip(this.components);
         this.label2 = new System.Windows.Forms.Label();
         this.panel2 = new System.Windows.Forms.Panel();
         this.pictureBox1 = new System.Windows.Forms.PictureBox();
         this.pictureBox2 = new System.Windows.Forms.PictureBox();
         this.panel1.SuspendLayout();
         this.panel2.SuspendLayout();
         this.SuspendLayout();
         // 
         // txtFile
         // 
         this.txtFile.Location = new System.Drawing.Point(20, 60);
         this.txtFile.Name = "txtFile";
         this.txtFile.Size = new System.Drawing.Size(402, 21);
         this.txtFile.TabIndex = 0;
         this.txtFile.Text = "";
         // 
         // btnBrowse
         // 
         this.btnBrowse.Image = ((System.Drawing.Bitmap)(resources.GetObject("btnBrowse.Image")));
         this.btnBrowse.ImageAlign = System.Drawing.ContentAlignment.BottomRight;
         this.btnBrowse.Location = new System.Drawing.Point(287, 10);
         this.btnBrowse.Name = "btnBrowse";
         this.btnBrowse.Size = new System.Drawing.Size(96, 35);
         this.btnBrowse.TabIndex = 1;
         this.btnBrowse.Text = "Browse...";
         this.btnBrowse.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
         this.tp.SetToolTip(this.btnBrowse, "Open a file to process");
         this.btnBrowse.Click += new System.EventHandler(this.btnBrowse_Click);
         // 
         // btnExit
         // 
         this.btnExit.Image = ((System.Drawing.Bitmap)(resources.GetObject("btnExit.Image")));
         this.btnExit.ImageAlign = System.Drawing.ContentAlignment.BottomLeft;
         this.btnExit.Location = new System.Drawing.Point(347, 349);
         this.btnExit.Name = "btnExit";
         this.btnExit.Size = new System.Drawing.Size(84, 35);
         this.btnExit.TabIndex = 2;
         this.btnExit.Text = "Exit";
         this.tp.SetToolTip(this.btnExit, "Exit programme");
         this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
         // 
         // btnRun
         // 
         this.btnRun.Image = ((System.Drawing.Bitmap)(resources.GetObject("btnRun.Image")));
         this.btnRun.ImageAlign = System.Drawing.ContentAlignment.BottomLeft;
         this.btnRun.Location = new System.Drawing.Point(347, 290);
         this.btnRun.Name = "btnRun";
         this.btnRun.Size = new System.Drawing.Size(84, 35);
         this.btnRun.TabIndex = 3;
         this.btnRun.Text = "Run";
         this.tp.SetToolTip(this.btnRun, "Process files");
         this.btnRun.Click += new System.EventHandler(new SelectFiles().calcFiles);

解决方案 »

  1.   


           // 
             // chkComment
             // 
             this.chkComment.Location = new System.Drawing.Point(28, 140);
             this.chkComment.Name = "chkComment";
             this.chkComment.Size = new System.Drawing.Size(210, 36);
             this.chkComment.TabIndex = 4;
             this.chkComment.Text = "Not involve Comment lines";
             this.chkComment.CheckedChanged += new System.EventHandler(this.chkComment_CheckedChanged);
             // 
             // chkBlank
             // 
             this.chkBlank.Location = new System.Drawing.Point(28, 94);
             this.chkBlank.Name = "chkBlank";
             this.chkBlank.Size = new System.Drawing.Size(215, 27);
             this.chkBlank.TabIndex = 5;
             this.chkBlank.Text = "Not involve Blank lines";
             this.chkBlank.CheckedChanged += new System.EventHandler(this.chkBlank_CheckedChanged);
             // 
             // panel1
             // 
             this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                                 this.chkCobol,
                                                                                 this.chkAsp,
                                                                                 this.chkC,
                                                                                 this.chkCpp,
                                                                                 this.chkCs,
                                                                                 this.chkJava});
             this.panel1.Location = new System.Drawing.Point(28, 214);
             this.panel1.Name = "panel1";
             this.panel1.Size = new System.Drawing.Size(272, 160);
             this.panel1.TabIndex = 6;
             // 
             // chkCobol
             // 
             this.chkCobol.Location = new System.Drawing.Point(159, 112);
             this.chkCobol.Name = "chkCobol";
             this.chkCobol.Size = new System.Drawing.Size(77, 28);
             this.chkCobol.TabIndex = 5;
             this.chkCobol.Text = "Cobol";
             this.chkCobol.CheckedChanged += new System.EventHandler(this.chkCobol_CheckedChanged);
             // 
             // chkAsp
             // 
             this.chkAsp.Location = new System.Drawing.Point(19, 112);
             this.chkAsp.Name = "chkAsp";
             this.chkAsp.Size = new System.Drawing.Size(74, 28);
             this.chkAsp.TabIndex = 4;
             this.chkAsp.Text = "asp";
             // 
             // chkC
             // 
             this.chkC.Location = new System.Drawing.Point(159, 65);
             this.chkC.Name = "chkC";
             this.chkC.Size = new System.Drawing.Size(77, 29);
             this.chkC.TabIndex = 3;
             this.chkC.Text = "c";
             // 
             // chkCpp
             // 
             this.chkCpp.Location = new System.Drawing.Point(19, 65);
             this.chkCpp.Name = "chkCpp";
             this.chkCpp.Size = new System.Drawing.Size(83, 29);
             this.chkCpp.TabIndex = 2;
             this.chkCpp.Text = "c++";
             // 
             // chkCs
             // 
             this.chkCs.Location = new System.Drawing.Point(159, 19);
             this.chkCs.Name = "chkCs";
             this.chkCs.Size = new System.Drawing.Size(77, 27);
             this.chkCs.TabIndex = 1;
             this.chkCs.Text = "c#";
             // 
             // chkJava
             // 
             this.chkJava.Location = new System.Drawing.Point(19, 19);
             this.chkJava.Name = "chkJava";
             this.chkJava.Size = new System.Drawing.Size(83, 27);
             this.chkJava.TabIndex = 0;
             this.chkJava.Text = "java";
             // 
             // label1
             // 
             this.label1.Location = new System.Drawing.Point(28, 206);
             this.label1.Name = "label1";
             this.label1.Size = new System.Drawing.Size(178, 18);
             this.label1.TabIndex = 7;
             this.label1.Text = "Select a filetype here";
             // 
             // linkLabel1
             // 
             this.linkLabel1.ActiveLinkColor = System.Drawing.Color.Blue;
             this.linkLabel1.Cursor = System.Windows.Forms.Cursors.Hand;
             this.linkLabel1.LinkVisited = true;
             this.linkLabel1.Location = new System.Drawing.Point(300, 140);
             this.linkLabel1.Name = "linkLabel1";
             this.linkLabel1.Size = new System.Drawing.Size(130, 66);
             this.linkLabel1.TabIndex = 8;
             this.linkLabel1.TabStop = true;
             this.linkLabel1.Text = "Made by Burning Ice,mail me for any question or bug report";
             this.linkLabel1.Visible = false;
             this.linkLabel1.VisitedLinkColor = System.Drawing.Color.Blue;
             this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
      

  2.   

    // 
             // linkLabel2
             // 
             this.linkLabel2.ActiveLinkColor = System.Drawing.Color.Blue;
             this.linkLabel2.Font = new System.Drawing.Font("SimSun", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
             this.linkLabel2.Location = new System.Drawing.Point(402, 0);
             this.linkLabel2.Name = "linkLabel2";
             this.linkLabel2.Size = new System.Drawing.Size(19, 19);
             this.linkLabel2.TabIndex = 9;
             this.linkLabel2.TabStop = true;
             this.linkLabel2.Tag = "";
             this.linkLabel2.Text = "H";
             this.tp.SetToolTip(this.linkLabel2, "display or hide help message");
             this.linkLabel2.VisitedLinkColor = System.Drawing.Color.Blue;
             this.linkLabel2.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel2_LinkClicked);
             // 
             // label2
             // 
             this.label2.Location = new System.Drawing.Point(31, 20);
             this.label2.Name = "label2";
             this.label2.Size = new System.Drawing.Size(235, 20);
             this.label2.TabIndex = 10;
             this.label2.Text = "Select a folder or files to process:";
             // 
             // panel2
             // 
             this.panel2.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                                 this.pictureBox1});
             this.panel2.Location = new System.Drawing.Point(10, 199);
             this.panel2.Name = "panel2";
             this.panel2.Size = new System.Drawing.Size(287, 190);
             this.panel2.TabIndex = 11;
             // 
             // pictureBox1
             // 
             this.pictureBox1.Image = ((System.Drawing.Bitmap)(resources.GetObject("pictureBox1.Image")));
             this.pictureBox1.Location = new System.Drawing.Point(10, 20);
             this.pictureBox1.Name = "pictureBox1";
             this.pictureBox1.Size = new System.Drawing.Size(266, 169);
             this.pictureBox1.TabIndex = 0;
             this.pictureBox1.TabStop = false;
             // 
             // pictureBox2
             // 
             this.pictureBox2.Image = ((System.Drawing.Bitmap)(resources.GetObject("pictureBox2.Image")));
             this.pictureBox2.Location = new System.Drawing.Point(256, 90);
             this.pictureBox2.Name = "pictureBox2";
             this.pictureBox2.Size = new System.Drawing.Size(174, 129);
             this.pictureBox2.TabIndex = 12;
             this.pictureBox2.TabStop = false;
             // 
             // LineCounter
             // 
             this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
             this.ClientSize = new System.Drawing.Size(435, 392);
             this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.pictureBox2,
                                                                          this.panel2,
                                                                          this.label2,
                                                                          this.linkLabel2,
                                                                          this.linkLabel1,
                                                                          this.label1,
                                                                          this.panel1,
                                                                          this.chkBlank,
                                                                          this.chkComment,
                                                                          this.btnRun,
                                                                          this.btnExit,
                                                                          this.btnBrowse,
                                                                          this.txtFile});
             this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
             this.MaximizeBox = false;
             this.Name = "LineCounter";
             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
             this.Text = "Line Counter";
             this.panel1.ResumeLayout(false);
             this.panel2.ResumeLayout(false);
             this.ResumeLayout(false);
      

  3.   

    this.btnRun.Click += new System.EventHandler(new SelectFiles().calcFiles);
    这样用的可真奇怪阿
      

  4.   

    new SelectFiles().calcFiles
    这是一个临时变量的成员函数
    等到你的btnRun click事件发生的时候也许这个临时变量都已经被回收了阿
      

  5.   

    这只是一个普通的delegate嘛,c#高级编程上就有这种例子。
    至于临时变量的问题,我改为先定义一个类成员,然后再在代理中调用这个方法,还是一样的
    错误。
    最令人气愤的是,我另写了一个简单的程序,结构跟这个差不多,居然一点错误都没有。
    真是没办法了。
      

  6.   

    找到了,是calcFiles的定义少了一个void返回符,呵呵,这种问题也怪难为人的。
    谢谢你了。接分