变量_未声明或从未分配错误

时间:2017-12-14 16:33:14

标签: c# windows forms

我使用的是Visual Studio 2017,每当我尝试打开NewComponentForm.cs[Design]时,我都会遇到此错误。

我已查找此错误,并且每个人都说您应该清理解决方案并重建并重新启动VS应用程序。在我的情况下,它根本没有帮助。

所以这是我需要添加功能的一些遗留代码,它的工作方式是在表单中使用5个视图,只需在某些按钮的帮助下更改Visible属性,错误是:

  

变量' LoadRemoteDescriptorsView'要么未申报,要么从未分配。

似乎LoadRemoteDescriptorsView视图是手动(由代码而不是设计师)添加到组件的,因为每次我添加一个按钮或其他控件时LoadRemoteDescriptorsView消息的代码。

这是代码的片段。注意:即使我选择“忽略并继续”,程序也能正常运行。当错误弹出时。

partial class NewComponentForm
{
    /// <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 Windows Form 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.PlatformButton = new System.Windows.Forms.Button();
        this.panel1 = new System.Windows.Forms.Panel();
        this.LoadRemoteDescriptorsButton = new System.Windows.Forms.Button();
        this.EditDeviceAmplifierButton = new System.Windows.Forms.Button();
        this.AddDeviceToAmplifierButton = new System.Windows.Forms.Button();
        this.ComponentPanel = new System.Windows.Forms.Panel();
        this.LoadRemoteDescriptorsView = new ExamplePlugins.DeviceMapper.View.LoadRemoteDescriptors();
        //LoadRemoteDescriptorsView = new LoadRemoteDescriptors();
        this.EditAmplifierDeviceOptionsView = new ExamplePlugins.DeviceMapper.View.EditAmplifierDeviceOptions();
        this.MainAcceptCancelButtonsPanel = new System.Windows.Forms.Panel();
        this.AcceptButton = new System.Windows.Forms.Button();
        this.CancelButton = new System.Windows.Forms.Button();
        this.NewAmplifierView = new ExamplePlugins.DeviceMapper.View.NewAmplifier();
        this.AddDeviceToAmplifierView = new ExamplePlugins.DeviceMapper.View.AddDeviceToAmplifier();
        this.NewDeviceView = new ExamplePlugins.DeviceMapper.View.NewDevice();
        this.DeviceButton = new System.Windows.Forms.Button();
        this.btnRegSettings = new System.Windows.Forms.Button();
        this.panel1.SuspendLayout();
        this.ComponentPanel.SuspendLayout();
        this.MainAcceptCancelButtonsPanel.SuspendLayout();
        this.SuspendLayout();
        /*****/
        /*****/SOME OTHER CODE HERE
        /*****/
        /*****/
        // 
        // ComponentPanel
        // 
        this.ComponentPanel.Controls.Add(this.LoadRemoteDescriptorsView); //Added
        this.ComponentPanel.Controls.Add(this.EditAmplifierDeviceOptionsView);
        this.ComponentPanel.Controls.Add(this.MainAcceptCancelButtonsPanel);
        this.ComponentPanel.Controls.Add(this.NewAmplifierView);
        this.ComponentPanel.Controls.Add(this.AddDeviceToAmplifierView);
        this.ComponentPanel.Controls.Add(this.NewDeviceView);
        this.ComponentPanel.Location = new System.Drawing.Point(116, 2);
        this.ComponentPanel.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
        this.ComponentPanel.Name = "ComponentPanel";
        this.ComponentPanel.Size = new System.Drawing.Size(803, 515);
        this.ComponentPanel.TabIndex = 4;
        //*******************************************************************************//
        // 
        // LoadRemoteDescriptorsView
        // 
        this.LoadRemoteDescriptorsView.Location = new System.Drawing.Point(19, 0);
        this.LoadRemoteDescriptorsView.Name = "LoadRemoteDescriptorsView";
        this.LoadRemoteDescriptorsView.Size = new System.Drawing.Size(670, 318);
        this.LoadRemoteDescriptorsView.TabIndex = 8;
        this.LoadRemoteDescriptorsView.Visible = false;
        //*******************************************************************************//
        // 

LoadRemoteDescriptorsViewInitializeComponent()函数

的早期声明
this.LoadRemoteDescriptorsView = new ExamplePlugins.DeviceMapper.View.LoadRemoteDescriptors();

当我们将该视图添加到组件面板

时,错误指向该行
this.ComponentPanel.Controls.Add(this.LoadRemoteDescriptorsView); //Added

我错过了什么?

0 个答案:

没有答案