Exposing usercontrol components at design time

G

Guest

Hi,

I want to allow design time modification of components on a usercontrol. I
added a listview called listView1 to the usercontrol, then added this
accessor method:

[Category("Components"),
Description("Set the listview parameters."),

DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public MyListView ListView
{
get { return listView1; }
}

This works great, almost. When the usercontrol is added to a form, I can
edit the ListView properties. Unfortunately, this line of coded is added to
my form's InitializeComponent() method:

this.userListView.Controls.Add(this.listView1.ListView);

I've read that usually you have to expose each property individually, but
exposing the entire control works except for the redundant "Add" above. And
with DesignerSerializationVisibility.Content I didn't expect the control
itself to be serialized, just the contents. If I delete the line above
everything is fine, but of course I don't want to have to edit
InitializeComponent().

Is there a way to eliminate the redundant listview "Add()"?

Thank you,
Gary
 
A

Atul

You can try applying the DesignerSerializationVisibility.Hidden attribute to
the Controls property of your USerControl.

----------------
-Atul, Sky Software http://www.ssware.com
Shell MegaPack For .Net & ActiveX
Windows Explorer GUI Controls
&
Quick-Launch Like Appbars, MSN/Office2003 Style Popups,
System Tray Icons and Shortcuts/Internet Shortcuts
 
G

Guest

Wow! That seems to do what I need! The name of the UserControl listview does
not get updated in the properties window until I reload the form, but I can
live with that given how simple the solution is.

I applied the DesignerSerializationVisibility.Hidden using the following
code - is this the proper way to do it?

Thanks so much,
Gary

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new ControlCollection Controls
{
get
{
return base.Controls;
}
}

Atul said:
You can try applying the DesignerSerializationVisibility.Hidden attribute to
the Controls property of your USerControl.

----------------
-Atul, Sky Software http://www.ssware.com
Shell MegaPack For .Net & ActiveX
Windows Explorer GUI Controls
&
Quick-Launch Like Appbars, MSN/Office2003 Style Popups,
System Tray Icons and Shortcuts/Internet Shortcuts
----------------



GP said:
Hi,

I want to allow design time modification of components on a usercontrol. I
added a listview called listView1 to the usercontrol, then added this
accessor method:

[Category("Components"),
Description("Set the listview parameters."),

DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public MyListView ListView
{
get { return listView1; }
}

This works great, almost. When the usercontrol is added to a form, I can
edit the ListView properties. Unfortunately, this line of coded is added
to
my form's InitializeComponent() method:

this.userListView.Controls.Add(this.listView1.ListView);

I've read that usually you have to expose each property individually, but
exposing the entire control works except for the redundant "Add" above.
And
with DesignerSerializationVisibility.Content I didn't expect the control
itself to be serialized, just the contents. If I delete the line above
everything is fine, but of course I don't want to have to edit
InitializeComponent().

Is there a way to eliminate the redundant listview "Add()"?

Thank you,
Gary
 

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