WinForm的继承设计师设置复制到派生形式设计师、形式、WinForm

2023-09-07 00:40:48 作者:盏茶作酒

我遇到与Visual Studio .NET 2008的一些令人讨厌的行为。

I am experiencing some annoying behavior with Visual Studio .NET 2008.

我们已经创建了一个基本形式和基本电网源自的Infragistics的UltraGrid。

We have created a base form, and a base grid derived from Infragistics UltraGrid.

在基地的形式,我们已经设置喜欢的颜色,字体大小等一些属性 1.创建一个新的Windows窗体(即DerivedForm) 2.我们将继承更改为基本形式,通过简单地添加一个using语句和更改继承的类定义。 3.在这一点上复制所有的属性设置的IDE你会在BaseForm.designer.cs看到DerivedForm.designer.cs。 4.现在,如果我们做出改变为基本形式的财产,它是由现有的设置覆盖,在步骤3中复制。因此,我们没有看到子窗体的新变化。

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.

什么是被复制的一个例子来自BaseForm.InitializeControls()之类的下面,我发现在派生Form类的InitializeControls():

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

有没有一种方法,以prevent从复制属性的子窗体?

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

推荐答案

只是我的2分钱小费......当我建立了我的基类中有颜色,字体,大小和这样的,在我的基类的定义,我做了一个统一的一致性覆盖的特性,使他们只读。因此,创建并包括所有额外的垃圾/膨胀,当你编译它第一次原始形态的时候,它会唠叨价值为只读,并要求你把衣服说行。然后,任何后续更改任何类(包括只读字体),所有的形式,文本框,标签,按钮等的将反映它们。这样的覆盖,使只读会...

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.