(c# 2.0) Custom control and don't take a line in the .designer.cs file when property change

Hello,

(escuse me for my english)

i make a new label (custom control) extended label.
i add a new property to choice the look (ErrorMessage, Title1, Title2, FieldCaption...). when the property is selected the control go to the setting file, take the parameters, and assign the properties.

for example errormessage -> forecolor = red; backcolor = yellow; textalign = middlecenter...

when i design a form, i take a new form, add my label, select the look type, the control go taake the paramters and assign the properties value. and it's ok, i can view my label with the good properties.

but in the .designer.cs file (InitializeComponent() method)lines are automically add (in alphabetical order).

Looktype = errormessage -> ok
but
textalign = middlecenter -> i don't want this because if i change the value in the setting to middleleft all my program are not correctly impact.

(when InitializeComponent() are computing he put looktype, this go take parameter and assign textalign = middleleft and go next line and take a new textalign to middlecenter. if property name first letter is before LookType, the look it's ok but he is two time affect and it's dirty. ).
i want to know how i can say for a property that he don't put a line in the InitializeComponent() methode when he is modified in design time)

thanks

f.lhermitte

[1447 byte] By [LHERMITTE] at [2007-12-16]
# 1
The easiest way to do what you are asking is to Shadow the properties you want to prevent the user changing. For you TextAlign example, your new property would look like this:


Public Shadows ReadOnly Property TextAlign() As ContentAlignment
Get
Return MyBase.TextAlign
End Get
End Property


This will show the text align property in the Property Grid, but will not allow editing.

Additionally, if you want data to not be serialized to the code (in initializecomponent) you can add the DesignerSerializationVisibility attribute to your property and pass it a value of hidden.

JacobGrass at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms Designer...