C# Can';我不明白为什么变量是未赋值的或未声明的

C# Can';我不明白为什么变量是未赋值的或未声明的,c#,winforms,visual-studio-2012,C#,Winforms,Visual Studio 2012,Visual Studio刚刚向我抛出了此警告屏幕: 我知道这意味着什么,但我不知道如何解决它。当我查看“InitializeComponent()”方法时,一切似乎都很好。它是一个自定义控件,由一个表和许多文本框组成。程序仍然可以编译得很好,没有错误。我在互联网上四处寻找解决方案,但没有一个例子真正适合我,我尝试的任何“修补程序”都没有真正解决任何问题 变量: private BiologiskFamiliePanel sdBiologiskFamiliePanel; 初始化组件: ...

Visual Studio刚刚向我抛出了此警告屏幕:

我知道这意味着什么,但我不知道如何解决它。当我查看“InitializeComponent()”方法时,一切似乎都很好。它是一个自定义控件,由一个表和许多文本框组成。程序仍然可以编译得很好,没有错误。我在互联网上四处寻找解决方案,但没有一个例子真正适合我,我尝试的任何“修补程序”都没有真正解决任何问题

变量:

private BiologiskFamiliePanel sdBiologiskFamiliePanel;
初始化组件:

...
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;
    }
}

我猜想,您可能在
BiologiskFamiliePanel
构造函数中有一些逻辑或初始化代码,这在设计器/加载时失败。请检查所有逻辑,您可能在
BiologiskFamiliePanel
构建阶段拥有这些逻辑。

我发现了问题所在

在我的BiologiskFamiliePanel.cs中,我有一个名为“VisData()”的函数。它基本上显示数据,因为它最初是不可见的


但是,构造函数通过调用“EnableField()”调用此方法,然后出现问题,因为您无法显示您没有的数据。

每当我在使用WinForms和设计器时遇到这些无法解释的错误时,“Microsoft修复程序”总是会将其清除。关闭并重新打开Visual Studio,或删除并重新添加变量。可能会删除.suo或.csproj.user文件以清除任何可能被卡住的文件。是否
this.sdGroupBox
null?我现在已经添加了该类中的所有代码。在visual studio重新启动后,请尝试“全部重建”命令尝试该操作,但不起作用。我有一个额外的构造函数,它接受了一个参数,但仍然使用相同的方法。但即使在我评论了这一点之后,我仍然得到了错误。否则,我没有任何其他初始化逻辑。@Vipar,“我有一个额外的构造函数,它接受了一个参数,但仍然使用相同的方法”。我很困惑。你为什么不发那条代码呢?我已经把全班的人都发了。
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;
        }
    }
}