c# - 该变量未声明或从未在 System.ComponentModel.Design.Serialization.CodeDomSerializerBase 中分配

标签 c# designer declaration

我是 C# 的新手,所以如果我提出愚蠢的问题,请原谅...

这是我的问题:

  • 我有一个继承自“TabPage”的类“ProtocolTabPage”。
  • 我有一个继承自“Panel”的“ControlPanel”。
  • 我有一个 ControlPanel 由我的 ProtocolTabPage 实例化。
  • 我的两个类都在命名空间“AutoTestProtocols.Interface”中。

ProtocolTabPage[Design] 中,我有以下错误:

"The variable 'ProtocolPanel' is either undeclared or was never assigned.

at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager manager, String exceptionText, String helpLink) at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression) at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression) at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)"

不过,在我的 ProtocolTabPage.Designer 中,我有

[...]
this.ProtocolPanel = new AutoTestProtocols.Interface.ControlPanel();
[...]
this.splitContainer1.Panel2.Controls.Add(this.ProtocolPanel);
[...]
this.ProtocolPanel.AutoScroll = true;
this.ProtocolPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.ProtocolPanel.Location = new System.Drawing.Point(0, 0);
this.ProtocolPanel.Name = "ProtocolPanel";
this.ProtocolPanel.Size = new System.Drawing.Size(696, 700);
this.ProtocolPanel.TabIndex = 0;
[...]
private AutoTestProtocols.Interface.ControlPanel ProtocolPanel;"

怎么了?

最佳答案

乍一看,您似乎在尝试使用类型名称作为变量名称,通常应该避免这种情况。在您的 ProtocolPanel 实例化中,尝试:

ProtocolPanel myProtocolPanel = new AutoTestProtocols.Interface.ControlPanel();

然后您可以将所有对“This.ProtocolPanel”的调用更改为“myProtocolPanel”。

关于c# - 该变量未声明或从未在 System.ComponentModel.Design.Serialization.CodeDomSerializerBase 中分配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/839044/

相关文章:

visual-studio - VS 2008 Windows 窗体使 "View Code"成为用户控件的默认值

c# - 创建使用 CollectionEditor 的自定义 IList 类

ios - 覆盖非动态类声明

循环结构声明C

c++ - 在 C++ 中重新声明变量是否有任何成本?

c# - 将投影点映射到真实世界点

c# - 在用户输入时加快记录过滤

c# - 使用哪一个 : Managed vs. 非托管哈希算法

c# oracle sql 准备语句

c# - 如何使设计器可以使用复合组件?