RE: Designer serialization of protected properties in derived classes

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi robrich,

Thanks for your post.

First, can you show me where do you initialize the mainPanel control, and
add it into Form.Controls collection? Normally, to make it appear in the
BaseForm designer, we should create it and add it into Form.Controls
collection in InitializeComponent() method, like this:

private void InitializeComponent()
{
this.mainPanel = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// mainPanel
//
this.mainPanel.BackColor = System.Drawing.SystemColors.Desktop;
this.mainPanel.Location = new System.Drawing.Point(24, 16);
this.mainPanel.Name = "mainPanel";
this.mainPanel.Size = new System.Drawing.Size(120, 120);
this.mainPanel.TabIndex = 1;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.mainPanel);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}

Normally, in baseform, if you marked the mainPanel as protected, like this:
protected Panel mainPanel;
protected Panel MainPanel
{
get
{
return this.mainPanel;
}
}

then in Inherited Form, you can drop controls onto the mainPanel without
any problem. Also, it will generate code correctly, like this:
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.mainPanel.SuspendLayout();
this.SuspendLayout();
//
// mainPanel
//
this.mainPanel.Controls.Add(this.button1);
this.mainPanel.Name = "mainPanel";
//
// button1
//
this.button1.Location = new System.Drawing.Point(32, 40);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(56, 32);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Name = "Form2";
this.mainPanel.ResumeLayout(false);
this.ResumeLayout(false);
}

I have attached the sample project in this reply. You can get it with
Outlook Express.

Hope this helps
================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Attachment:
codeserializationtest.zip


Description: Binary data