views:

195

answers:

2

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 copies 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():

enter code here

//
// 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);

enter code here

Is there a way to prevent the IDE from copying properties to the child form?

A: 

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)

BioBuckyBall
Yes. I can build, and I'm sure this is what Microsoft developers intended. I would just like to see different behavior from the IDE, and prevent it if possible.
Blanthor
What I mean is, the changes don't get copied until I build. Then the new property values are copied into the subclass again. Isn't that not what you wanted? I thought your issue was that changes were not copied from base -> derived after the initial time. editing answer for clarity...
BioBuckyBall
A: 

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.

DRapp
I gave this a try. This does seem to be working (i.e. It's breaking existing derived classes). I won't be able to resize in the designer anymore, but I should be able to expose these in the properties tab. I'll update this once a complete test is done.
Blanthor
Additionally, I've even gone one level further with some "constants" defined, such as fonts, colors, etc so all labels, buttons, radio, textboxes, etc point to the "CONSTANT". Then, if I want to change a color or size or font family, one change of the constant and ALL is impacted downstream. -- Inheritence is great.
DRapp