WinForm Inheritance designer settings are copied to derived form
I am experiencing some annoying behavior with Visual Studio .NET 2008.
We have created a base form, and a base grid derived from Infragistics UltraGrid.
In the base form, we have set some properties like colors, font size, etc. 1. We create a new Windows Form, (i.e. DerivedForm) 2. We change the inheritance to BaseForm, by simply adding a using statement and changing the inheritance in the class definition. 3. The IDE at this point copie开发者_开发知识库s all of the property settings you would see in BaseForm.designer.cs to DerivedForm.designer.cs. 4. Now if we make a change to a BaseForm property, it is overridden by the existing settings, copied in step 3. Therefore we don’t see the new change in the child form.
An example of what is being copied comes from BaseForm.InitializeControls() like the following, which I find in the derived Form class’s InitializeControls():
//
// BaseForm_Fill_Panel
//
this.BaseForm_Fill_Panel.Location = new System.Drawing.Point(0, 47);
this.BaseForm_Fill_Panel.Size = new System.Drawing.Size(1095, 505);
Is there a way to prevent the IDE from copying properties to the child form?
Just my 2cents... When I built my baseclasses to have a uniform consistency of colors, fonts, sizes and such, in my baseclass definition, I did an override on the properties to make them read-only. So, when the original form is created and includes all that extra garbage/bloat, when you compile it first time, it will nag about a value as read-only and require you to strip said lines. Then, any subsequent changes to any of the classes (including read-only fonts), ALL the forms, textboxes, labels, buttons, etc will reflect them. Such override to make read-only would be...
[ReadOnly(true)]
public override Color ForeColor
{ get { return Color.Blue; } }
[ReadOnly(true)]
public override Font Font
{ get { return new Font(GDITFontBaseName, GDITFontBaseSize, FontStyle.Regular, GraphicsUnit.Point); } }
I don't know if this is what you are really trying to get accomplished, but in my stuff, works great.
I just tried it in 2005, it does the same thing, so I think it is "working as intended"
Edit:
Until I build....Did you build?
edit2:
This is the behavior I see. Let me know if this is what you want and if not, how you want it to be different.
1. Create base form, edit some property, say background = blue
2. Create derived form, background property will be blue
3. change base form, say background = red
4. look at derived form properties. change from 3 not reflected (ie background is still blue).
5. build
6. derived form now reflects change from 3 (ie background is now red)
精彩评论