2012-07-26 55 views
0

我不小心從我的項目之一去除引用,然後小心翼翼地把它們放回,但現在我扔在代碼中的錯誤將被完全正常,所以我想我一定還是會丟失,除非參考在這個過程中有其他東西被打破了。下面是電流誤差:的Visual Studio Express的2010和參考文檔版本

The variable 'button1' is either undeclared or was never assigned. 

但這裏是Form1.Designer.cs代碼:

private void InitializeComponent() 
    { 
     this.button1 = new System.Windows.Forms.Button(); 
     ... 
     // 
     // button1 
     // 
     this.button1.Location = new System.Drawing.Point(235, 382); 
     this.button1.Name = "button1"; 
     this.button1.Size = new System.Drawing.Size(125, 23); 
     this.button1.TabIndex = 0; 
     this.button1.Text = "Generate Report"; 
     this.button1.UseVisualStyleBackColor = true; 
     this.button1.Click += new System.EventHandler(this.button1_Click); 
     ... 
     this.Controls.Add(this.button1); 
     ... 
     private System.Windows.Forms.Button button1; 

最後七個線全部拋出這個錯誤。任何建議表示讚賞。

問候。

編輯:這裏是相關的評論代碼:

public partial class Severity3RetailNetworkTrackingLog : Form 
{ 
    public Severity3RetailNetworkTrackingLog() 
    { 
     InitializeComponent(); 
    } 

private void InitializeComponent() 
    { 
     this.button1 = new System.Windows.Forms.Button(); 

凡Form1中已更改爲Severity3RetailNetworkTrackingLog。

+0

聽起來像Button1的不宣。應該有一行:Button Button1; – RedEyedMonster 2012-07-26 14:52:36

+0

這不是你引用一個問題,或者你會得到相關嘗試使用類型的按鈕,而不是一個實例相關的異常的異常。你似乎錯過了你的Button聲明。 Button button1 = new Button(); – CSharpened 2012-07-26 14:57:36

回答

0

我懷疑你缺少的成員變量定義

class Form1 { 
    /* lots of windows form designer code */ 

    /* some other member variables */ 
    System.Windows.Forms.Button button1; 
} 

在您的類定義。

0

原來,VS快訊2010年只是行爲不端。我評論了所有有問題的代碼,仍然得到了與同一行號同樣的錯誤。所以我關閉和打開VS,一切都恢復正常。