Visual Studio的只是把這個警告屏幕看着我:想不通爲什麼變量是未分配或未申報
我知道這意味着什麼,但我無法弄清楚如何解決它。當我查看「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;
}
}
}
任何時候我在使用WinForms和設計器時都會遇到這些無法解釋的錯誤,因此「微軟修復」一直將其清除。關閉並重新打開Visual Studio,或者刪除並重新添加變量。可能會刪除.suo或.csproj.user文件以清除可能卡住的內容。 –
'this.sdGroupBox' null? –
我現在已經添加了該類的所有代碼。 – OmniOwl