我是 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/