Designer throws Excepion : [System.ComponentModel.Browsable(false)] seems not to work as expected.

S

Sagaert Johan

hi

In a componenet class i have a property with the attribute
[System.ComponentModel.Browsable(false)]

public int Vsetting

{

set{....}

get{...}

}



When i use the component on a form, the property is not visible in de
peoperties window of the designer (thats ok)

But still the IDE seems to put a line in the form.designer.cs

Vsetting=10;

How can i avoid the IDE inserting that ?



Johan
 
S

Stoitcho Goutsev \(100\)

Sagaert,

The fact that the property is not visible doesn't meen it is not going to be
serialized in the code.
There are couple of ways you can prevent this.

1. Specify propertie's default value. The designer won't serialize
properties, which has been set to their default values. You can do that
using DefaultValueAttribute attribute or for more complex scenarios you can
provide ShouldSerializeXXXX method

2. Using DesignerSerializationVisibilityAttribute. If you add
DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)
to your property its value won't be serialized into the code regardless of
its value.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top