PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Framework Forms Exposing usercontrol components at design time

Reply

Exposing usercontrol components at design time

 
Thread Tools Rate Thread
Old 18-10-2005, 07:15 PM   #1
=?Utf-8?B?R1A=?=
Guest
 
Posts: n/a
Default Exposing usercontrol components at design time


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

  Reply With Quote
Old 19-10-2005, 11:43 AM   #2
Atul
Guest
 
Posts: n/a
Default Re: Exposing usercontrol components at design time

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" <GP@discussions.microsoft.com> wrote in message
news:6F382B48-8376-4944-853B-592C8D73B46C@microsoft.com...
> 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
>



  Reply With Quote
Old 20-10-2005, 04:07 PM   #3
=?Utf-8?B?R1A=?=
Guest
 
Posts: n/a
Default Re: Exposing usercontrol components at design time

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" wrote:

> 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" <GP@discussions.microsoft.com> wrote in message
> news:6F382B48-8376-4944-853B-592C8D73B46C@microsoft.com...
> > 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
> >

>
>
>

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off