C# Designer error

cdeclarationdesigner

I'm a newbie to C# so please excuse me if I ask dumb questions…

Here is my problem :

  • I have a class "ProtocolTabPage" that inherits from "TabPage".
  • I have a "ControlPanel" that inherits from "Panel".
  • I have a ControlPanel instanced by my ProtocolTabPage.
  • Both my classes are in the namespace "AutoTestProtocols.Interface".

In the ProtocolTabPage[Design], I have the following errors :

"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)"

Though, in my ProtocolTabPage.Designer, I have

[...]
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;"

What's wrong ?

Best Answer

Just at first blush it looks like you're trying to use a Type name as a variable name, which should generally be avoided. In your ProtocolPanel instantiation, try:

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

Then you can just change all of those calls to "This.ProtocolPanel" to "myProtocolPanel."

Related Topic