gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 17:24:31 25 4
gpt4 key购买 nike

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

这是我的问题:

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

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

"The variable 'ProtocolPanel' is either undeclared or was neverassigned.

atSystem.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManagermanager, String exceptionText, String helpLink) atSystem.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManagermanager, String name, CodeExpression expression) atSystem.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManagermanager, String name, CodeExpression expression) atSystem.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManagermanager, 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com