2013-11-25 50 views
0

Visual Studio的只是把這個警告屏幕看着我:想不通爲什麼變量是未分配或未申報

enter image description here

我知道這意味着什麼,但我無法弄清楚如何解決它。當我查看「InitializeComponent()」方法時,一切似乎都很好。這是一個由表格和大量文本框組成的自定義控件。該程序仍然可以毫無錯誤地編譯。我在網上找了一遍找到解決方案,但沒有一個例子真的適合我,我試過的「修補程序」並沒有真正解決任何問題。

變量:

private BiologiskFamiliePanel sdBiologiskFamiliePanel; 

的InitializeComponent:

... 
this.sdBiologiskFamiliePanel = new Smart_Journal.Controls.BiologiskFamiliePanel(); 
... 
this.sdGroupBox.Controls.Add(this.sdBiologiskFamiliePanel); // Where the Error Message put me 
... 
this.sdBiologiskFamiliePanel.Location = new System.Drawing.Point(6, 338); 
this.sdBiologiskFamiliePanel.Name = "sdBiologiskFamiliePanel"; 
this.sdBiologiskFamiliePanel.Size = new System.Drawing.Size(329, 272); 
this.sdBiologiskFamiliePanel.TabIndex = 2; 

你能點的東西,我已經錯過了明顯?

編輯:

StamDataPanel.Designer.cs

using Smart_Journal.Controls; 

namespace Smart_Journal.Controls 
{ 
    partial class StamDataPanel 
    { 
     /// <summary> 
     /// Required designer variable. 
     /// </summary> 
     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); 
     } 

     #region Component Designer generated code 

     /// <summary> 
     /// Required method for Designer support - do not modify 
     /// the contents of this method with the code editor. 
     /// </summary> 
     private void InitializeComponent() 
     { 
      this.sdGroupBox = new System.Windows.Forms.GroupBox(); 
      this.sdPlejeFamiliePanel = new Smart_Journal.Controls.PlejeFamiliePanel(); 
      this.sdBiologiskFamiliePanel = new Smart_Journal.Controls.BiologiskFamiliePanel(); 
      this.sdPlejeBarnPanel = new Smart_Journal.Controls.PlejeBarnPanel(); 
      this.sdMenuStrip = new System.Windows.Forms.MenuStrip(); 
      this.filerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 
      this.sdGemItem = new System.Windows.Forms.ToolStripMenuItem(); 
      this.visToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 
      this.sdVisPlejeboernItem = new System.Windows.Forms.ToolStripMenuItem(); 
      this.sdVisBFamilieItem = new System.Windows.Forms.ToolStripMenuItem(); 
      this.sdVisKursusListeItem = new System.Windows.Forms.ToolStripMenuItem(); 
      this.sdVisVederlagItem = new System.Windows.Forms.ToolStripMenuItem(); 
      this.sdVisAlleItem = new System.Windows.Forms.ToolStripMenuItem(); 
      this.sdPlejeFamilieKursusListePanel = new Smart_Journal.Controls.PlejeFamilieKursusListePanel(); 
      this.sdPlejeFamilieAndreBornPanel = new Smart_Journal.Controls.PlejeFamilieAndreBornPanel(); 
      this.sdPlejeFamilieVedlagPanel = new Smart_Journal.Controls.PlejeFamilieVedlagPanel(); 
      this.sdGroupBox.SuspendLayout(); 
      this.sdMenuStrip.SuspendLayout(); 
      this.SuspendLayout(); 
      // 
      // sdGroupBox 
      // 
      this.sdGroupBox.Controls.Add(this.sdPlejeFamiliePanel); 
      this.sdGroupBox.Controls.Add(this.sdBiologiskFamiliePanel); 
      this.sdGroupBox.Controls.Add(this.sdPlejeBarnPanel); 
      this.sdGroupBox.Location = new System.Drawing.Point(3, 27); 
      this.sdGroupBox.Name = "sdGroupBox"; 
      this.sdGroupBox.Size = new System.Drawing.Size(644, 610); 
      this.sdGroupBox.TabIndex = 0; 
      this.sdGroupBox.TabStop = false; 
      this.sdGroupBox.Text = "Stamdata"; 
      // 
      // sdPlejeFamiliePanel 
      // 
      this.sdPlejeFamiliePanel.AutoSize = true; 
      this.sdPlejeFamiliePanel.Location = new System.Drawing.Point(337, 19); 
      this.sdPlejeFamiliePanel.Name = "sdPlejeFamiliePanel"; 
      this.sdPlejeFamiliePanel.RightToLeft = System.Windows.Forms.RightToLeft.No; 
      this.sdPlejeFamiliePanel.Size = new System.Drawing.Size(296, 415); 
      this.sdPlejeFamiliePanel.TabIndex = 3; 
      // 
      // sdBiologiskFamiliePanel 
      // 
      this.sdBiologiskFamiliePanel.Location = new System.Drawing.Point(6, 338); 
      this.sdBiologiskFamiliePanel.Name = "sdBiologiskFamiliePanel"; 
      this.sdBiologiskFamiliePanel.Size = new System.Drawing.Size(329, 272); 
      this.sdBiologiskFamiliePanel.TabIndex = 2; 
      // 
      // sdPlejeBarnPanel 
      // 
      this.sdPlejeBarnPanel.AutoSize = true; 
      this.sdPlejeBarnPanel.Bemaerkninger = null; 
      this.sdPlejeBarnPanel.Location = new System.Drawing.Point(2, 19); 
      this.sdPlejeBarnPanel.Name = "sdPlejeBarnPanel"; 
      this.sdPlejeBarnPanel.Size = new System.Drawing.Size(329, 313); 
      this.sdPlejeBarnPanel.TabIndex = 0; 
      this.sdPlejeBarnPanel.TideligereForanstaltninger = null; 
      // 
      // sdMenuStrip 
      // 
      this.sdMenuStrip.AllowMerge = false; 
      this.sdMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 
      this.filerToolStripMenuItem, 
      this.visToolStripMenuItem}); 
      this.sdMenuStrip.Location = new System.Drawing.Point(0, 0); 
      this.sdMenuStrip.Name = "sdMenuStrip"; 
      this.sdMenuStrip.Size = new System.Drawing.Size(918, 24); 
      this.sdMenuStrip.TabIndex = 3; 
      this.sdMenuStrip.Text = "menuStrip1"; 
      // 
      // filerToolStripMenuItem 
      // 
      this.filerToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { 
      this.sdGemItem}); 
      this.filerToolStripMenuItem.Name = "filerToolStripMenuItem"; 
      this.filerToolStripMenuItem.ShortcutKeyDisplayString = ""; 
      this.filerToolStripMenuItem.Size = new System.Drawing.Size(41, 20); 
      this.filerToolStripMenuItem.Text = "Filer"; 
      // 
      // sdGemItem 
      // 
      this.sdGemItem.Name = "sdGemItem"; 
      this.sdGemItem.ShortcutKeyDisplayString = "Ctrl + S"; 
      this.sdGemItem.Size = new System.Drawing.Size(203, 22); 
      this.sdGemItem.Text = "Gem Ændringer"; 
      this.sdGemItem.Click += new System.EventHandler(this.sdGemItem_Click); 
      // 
      // visToolStripMenuItem 
      // 
      this.visToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { 
      this.sdVisPlejeboernItem, 
      this.sdVisBFamilieItem, 
      this.sdVisKursusListeItem, 
      this.sdVisVederlagItem, 
      this.sdVisAlleItem}); 
      this.visToolStripMenuItem.Name = "visToolStripMenuItem"; 
      this.visToolStripMenuItem.Size = new System.Drawing.Size(34, 20); 
      this.visToolStripMenuItem.Text = "Vis"; 
      // 
      // sdVisPlejeboernItem 
      // 
      this.sdVisPlejeboernItem.Name = "sdVisPlejeboernItem"; 
      this.sdVisPlejeboernItem.ShortcutKeyDisplayString = ""; 
      this.sdVisPlejeboernItem.Size = new System.Drawing.Size(163, 22); 
      this.sdVisPlejeboernItem.Text = "Andre Plejebørn"; 
      this.sdVisPlejeboernItem.Click += new System.EventHandler(this.sdVisPlejeboernItem_Click); 
      // 
      // sdVisBFamilieItem 
      // 
      this.sdVisBFamilieItem.Name = "sdVisBFamilieItem"; 
      this.sdVisBFamilieItem.Size = new System.Drawing.Size(163, 22); 
      this.sdVisBFamilieItem.Text = "Biologisk Familie"; 
      this.sdVisBFamilieItem.Click += new System.EventHandler(this.sdVisBFamilieItem_Click); 
      // 
      // sdVisKursusListeItem 
      // 
      this.sdVisKursusListeItem.Name = "sdVisKursusListeItem"; 
      this.sdVisKursusListeItem.Size = new System.Drawing.Size(163, 22); 
      this.sdVisKursusListeItem.Text = "Kursus Liste"; 
      this.sdVisKursusListeItem.Click += new System.EventHandler(this.sdVisKursusListeItem_Click); 
      // 
      // sdVisVederlagItem 
      // 
      this.sdVisVederlagItem.Name = "sdVisVederlagItem"; 
      this.sdVisVederlagItem.Size = new System.Drawing.Size(163, 22); 
      this.sdVisVederlagItem.Text = "Vederlag"; 
      this.sdVisVederlagItem.Click += new System.EventHandler(this.sdVisVederlagItem_Click); 
      // 
      // sdVisAlleItem 
      // 
      this.sdVisAlleItem.Name = "sdVisAlleItem"; 
      this.sdVisAlleItem.Size = new System.Drawing.Size(163, 22); 
      this.sdVisAlleItem.Text = "Vis Alle"; 
      this.sdVisAlleItem.Click += new System.EventHandler(this.sdVisAlleItem_Click); 
      // 
      // sdPlejeFamilieKursusListePanel 
      // 
      this.sdPlejeFamilieKursusListePanel.Location = new System.Drawing.Point(652, 27); 
      this.sdPlejeFamilieKursusListePanel.Name = "sdPlejeFamilieKursusListePanel"; 
      this.sdPlejeFamilieKursusListePanel.Size = new System.Drawing.Size(262, 195); 
      this.sdPlejeFamilieKursusListePanel.TabIndex = 5; 
      // 
      // sdPlejeFamilieAndreBornPanel 
      // 
      this.sdPlejeFamilieAndreBornPanel.Location = new System.Drawing.Point(653, 387); 
      this.sdPlejeFamilieAndreBornPanel.Name = "sdPlejeFamilieAndreBornPanel"; 
      this.sdPlejeFamilieAndreBornPanel.Size = new System.Drawing.Size(262, 210); 
      this.sdPlejeFamilieAndreBornPanel.TabIndex = 4; 
      // 
      // sdPlejeFamilieVedlagPanel 
      // 
      this.sdPlejeFamilieVedlagPanel.Location = new System.Drawing.Point(652, 228); 
      this.sdPlejeFamilieVedlagPanel.Name = "sdPlejeFamilieVedlagPanel"; 
      this.sdPlejeFamilieVedlagPanel.Size = new System.Drawing.Size(262, 156); 
      this.sdPlejeFamilieVedlagPanel.TabIndex = 2; 
      // 
      // StamDataPanel 
      // 
      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 
      this.AutoSize = true; 
      this.Controls.Add(this.sdPlejeFamilieKursusListePanel); 
      this.Controls.Add(this.sdPlejeFamilieAndreBornPanel); 
      this.Controls.Add(this.sdPlejeFamilieVedlagPanel); 
      this.Controls.Add(this.sdGroupBox); 
      this.Controls.Add(this.sdMenuStrip); 
      this.Name = "StamDataPanel"; 
      this.Size = new System.Drawing.Size(918, 640); 
      this.sdGroupBox.ResumeLayout(false); 
      this.sdGroupBox.PerformLayout(); 
      this.sdMenuStrip.ResumeLayout(false); 
      this.sdMenuStrip.PerformLayout(); 
      this.ResumeLayout(false); 
      this.PerformLayout(); 

     } 

     #endregion 

     private System.Windows.Forms.GroupBox sdGroupBox; 
     private BiologiskFamiliePanel sdBiologiskFamiliePanel; 
     private PlejeBarnPanel sdPlejeBarnPanel; 
     private PlejeFamilieVedlagPanel sdPlejeFamilieVedlagPanel; 
     private System.Windows.Forms.MenuStrip sdMenuStrip; 
     private System.Windows.Forms.ToolStripMenuItem visToolStripMenuItem; 
     private System.Windows.Forms.ToolStripMenuItem sdVisPlejeboernItem; 
     private System.Windows.Forms.ToolStripMenuItem sdVisBFamilieItem; 
     private System.Windows.Forms.ToolStripMenuItem sdVisKursusListeItem; 
     private System.Windows.Forms.ToolStripMenuItem sdVisVederlagItem; 
     private System.Windows.Forms.ToolStripMenuItem sdVisAlleItem; 
     private System.Windows.Forms.ToolStripMenuItem filerToolStripMenuItem; 
     private System.Windows.Forms.ToolStripMenuItem sdGemItem; 
     private PlejeFamiliePanel sdPlejeFamiliePanel; 
     private Controls.PlejeFamilieAndreBornPanel sdPlejeFamilieAndreBornPanel; 
     private PlejeFamilieKursusListePanel sdPlejeFamilieKursusListePanel; 
    } 
} 

StamDataPanel.cs

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Drawing; 
using System.Data; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using Smart_Journal.Controls; 
using Smart_Journal.Familie; 

namespace Smart_Journal.Controls 
{ 
    public partial class StamDataPanel : UserControl 
    { 
     public StamDataPanel(PlejeBarn p) 
     { 
      InitializeComponent(); 

     } 

     public StamDataPanel() 
     { 
      InitializeComponent(); 
     } 

     private void sdGemItem_Click(object sender, EventArgs e) 
     { 
      Utility.GemStamdata(this); 
     } 

     private void sdVisPlejeboernItem_Click(object sender, EventArgs e) 
     { 
      //sdPlejeFamilieAndreBornPanel 
     } 

     private void sdVisBFamilieItem_Click(object sender, EventArgs e) 
     { 
      //sdBiologiskFamiliePanel.EnableFields(true); 
     } 

     private void sdVisKursusListeItem_Click(object sender, EventArgs e) 
     { 

     } 

     private void sdVisVederlagItem_Click(object sender, EventArgs e) 
     { 

     } 

     private void sdVisAlleItem_Click(object sender, EventArgs e) 
     { 

     } 

     public PlejeBarnPanel PlejeBarnPanelObjekt() 
     { 
      return sdPlejeBarnPanel; 
     } 

     public PlejeFamiliePanel PlejeFamiliePanelObjekt() 
     { 
      return sdPlejeFamiliePanel; 
     } 

     public PlejeFamilieVedlagPanel PlejeFamilieVedlagPanelObjekt() 
     { 
      return sdPlejeFamilieVedlagPanel; 
     } 

     public PlejeFamilieKursusListePanel PlejeFamilieKursusListePanelObjekt() 
     { 
      return sdPlejeFamilieKursusListePanel; 
     } 

     public PlejeFamilieAndreBornPanel PlejeFamilieAndreBornPanelObjekt() 
     { 
      return sdPlejeFamilieAndreBornPanel; 
     } 

     public BiologiskFamiliePanel BiologiskFamiliePanelObjekt() 
     { 
      return sdBiologiskFamiliePanel; 
     } 
    } 
} 
+1

任何時候我在使用WinForms和設計器時都會遇到這些無法解釋的錯誤,因此「微軟修復」一直將其清除。關閉並重新打開Visual Studio,或者刪除並重新添加變量。可能會刪除.suo或.csproj.user文件以清除可能卡住的內容。 –

+1

'this.sdGroupBox' null? –

+0

我現在已經添加了該類的所有代碼。 – OmniOwl

回答

0

我想,你可能有BiologiskFamiliePanel構造,這是中的一些邏輯或初始化代碼在設計師/負荷上失敗。請檢查所有邏輯,您可能在BiologiskFamiliePanel構建階段使用它。

+0

我有一個額外的構造函數採取了一個參數,但仍然使用相同的方法。但即使在我評論出來後,我仍然有錯誤。否則,我沒有任何其他初始化邏輯。 – OmniOwl

+0

@Vipar,「我有一個額外的構造函數接受了一個參數,但仍然使用了相同的方法」。我很困惑。你爲什麼不發佈該代碼 – Nair

+0

我已經發布了該課程的其餘部分。 – OmniOwl

0

我找出了問題所在。

在我的BiologiskFamiliePanel.cs中,我有一個名爲「VisData()」的函數。它基本上顯示數據,因爲它最初不可見。

但是構造函數通過調用「EnableField()」調用此方法,然後出現此問題,因爲您無法顯示您沒有的數據。