Hiding properties from the Forms Designer

P

Phill. W

(VB.Net 2003)
I have a UserControl that exposes a number of public properties.

When using this control on a.n.other Form, how can(?) I prevent
the Forms Designer from adding code into InitializeComponent to
set any or all of these properties when I save the form?

There are one or two that I /might/ want set in this way, but I'd like
to "persuade" the Designer to leave the rest well alone ...

Any suggestions?
TIA,
Phill W.
 
H

Herfried K. Wagner [MVP]

Phill. W said:
I have a UserControl that exposes a number of public properties.

When using this control on a.n.other Form, how can(?) I prevent
the Forms Designer from adding code into InitializeComponent to
set any or all of these properties when I save the form?

\\\
< _
DesignerSerializationVisibility( _
DesignerSerializationVisibility.Hidden _
) _
Public Property...
///
 
B

Bob Powell [MVP]

There are several ways to do this. People will often refer to the
BrowsableAttribute and override of the relavent properties. This however is
an inefficient and incorrect way to do things.

At design time, the IDE provides for the dedicated control designer assigned
to your component to filter the properties and events so that they are not
seen by the IDE. This is accomplished using the
ControlDesigner.PreFilterProperties and ControlDesigner PostFilterProperties
methods. Furthermore, if you use reflection or indeed the PropertyGrid at
runtime you can create custom filters by having your class implement the
ICustomTypeDescriptor interface. This enables you to return an edited or
even augmented list of properties, events and attributes seen by the
reflection API's

Of course, at runtime the properties will still be available but if the
properties are filtered at design time they will not be visible to the code
serializer. IMO it's simpler to provide a designer with a property filter
than override N number of properties and mess with their browsability.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 

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