Designer serialization of protected properties in derived classes

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I'm using Visual Studio 2003 on a Windows XP machine. I've tried this in
various circumstances, and narrowed it down to this simple example:

I've got a base form called BaseForm defined like so:
public class BaseForm : System.Windows.Forms.Form { ...

It has a protected property called "MainPanel" which looks like so:
protected Panel MainPanel {
get { return this.mainPanel; }
}

this.mainPanel is a Panel that works perfectly in design mode on BaseForm.

I've got a class that derives from BaseForm defined like so:
public class DerivedForm : BaseForm { ...

I can drop controls onto DerivedForm onto MainPanel in design mode, all is
well. I look at the Designer Generated Code, and they aren't added to
MainPanel's Control array. I can add code like this, and it works ok:
this.MainPanel.Controls.Add(this.label1);

Every time I make a change in the DerivedForm in design mode, it re-creates
the Designer Generated Code, removes my MainPanel.Controls.Add line, and a
subsequent build removes the controls from the form.

I've tried adding these designer attributes to the protected MainPanel
definition to no avail:
[
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
NotifyParentProperty(true)
]
protected Panel MainPanel {
get { return this.mainPanel; }
}

It has become quite a chore to re-add all the
this.MainPanel.Add(this.Control); lines back in every time. How do I get the
designer to serialize protected properties like this?

robrich
robrich@xxxxxxxxxxxxxxxx
.



Relevant Pages

  • Re: Does C#.Net support Layout managers?
    ... make much sense to me to rely on the designer for some controls, ... designer cannot help you complete. ... I seem to use generic Lists. ... The code I'm specifically talking about is the layout code. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Deriving - .NET example
    ... A Form class has fairly large interface which can be used to manipulate the window. ... This includes methods/properties such as changing window position/size, setting its style, back color, caption etc. as well as adding child controls. ... When designing custom form via MS Visual Studio designer, the corresponding C# code is designed which uses the aforementioned class Form and its interface to achieve the look created in the designer. ... Within the UI subsystem some sort of factory object would field that request and do the actual instantiation and initialization. ...
    (comp.object)
  • Re: Visual Basic 2005 - designer.vb page problem
    ... In order to eliminate this problem, I decided to move all the declarations ... This way the designer doesn't perform ... only standard ASP.NET controls or can you repro the problem through a very ... changed some thing in .aspx page. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Does C#.Net support Layout managers?
    ... That's not the scenario for which I'm advocating the designer. ... the logic is in the business layer. ... When the controls need to be set up dynamically using logic, ... Refactoring tools built into VS2005 now, but working with them, I've ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Does C#.Net support Layout managers?
    ... CANNOT set on the designer. ... Its rather silly to have an array of controls. ... The designer is a code generator itself, ... A lot of Windows UI code was thrown away when the Web became ...
    (microsoft.public.dotnet.languages.csharp)