469,354 Members | 2,255 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,354 developers. It's quick & easy.

Advanced UserControl Question

The ToolBar control allows you to add toolbar buttons. When you add a button,
the button is not only displayed in the toolbar, but also added as a
separator control in the form/usercontrol your toolbar exists in.

I'm writing my own usercontrol which contains various different controls
(e.g. Panel, Button). I would like these controls to be listed in the drop
down just above the Properties grid, when a new instance of the usercontrol
is added to the form. This will allow the user to select the controls and
customize them.

I also want to allow the user to able to click on the controls in the
usercontrol to select them and display their property values in the Property
Grid.

Can someone please show me a C# example on how to do this.

Thank you.

Regards
Mark
Sep 18 '06 #1
2 2658
Hi Mark,

The difference between the ToolBars functionality and your UserControl is that you are explicitly adding the ToolBar buttons at
design-time, but when you include your UserControl its Panel and Buttons are already there. This means that your nested Controls
are not being managed by the designer.

A UserControl is meant to be an encapsulated, composite control. In other words, it contains controls and makes them appear and
function as a single control in the designer.

One option would be to define public properties for each of the controls that you want publicly configurable at design-time:

[Category("Appearance"), TypeConverter(typeof(ExpandableObjectConverter))]
public Button Button1
{
get { return button1; }
}

With the above code button1 will be configurable via the PropertyGrid at design-time through the Button1 property. This does,
however, defeat the purpose of a UserControl to an extent.

You might want to look in to creating a custom designer for your control, but I'm not sure if you'll be able to accomplish your goal
that way:

IDesigner on MSDN:
http://msdn2.microsoft.com/en-us/lib...idesigner.aspx

DesignerAttribute on MSDN:
http://msdn2.microsoft.com/en-us/lib...attribute.aspx

--
Dave Sexton

"Mark Collard" <Ma*********@discussions.microsoft.comwrote in message news:C6**********************************@microsof t.com...
The ToolBar control allows you to add toolbar buttons. When you add a button,
the button is not only displayed in the toolbar, but also added as a
separator control in the form/usercontrol your toolbar exists in.

I'm writing my own usercontrol which contains various different controls
(e.g. Panel, Button). I would like these controls to be listed in the drop
down just above the Properties grid, when a new instance of the usercontrol
is added to the form. This will allow the user to select the controls and
customize them.

I also want to allow the user to able to click on the controls in the
usercontrol to select them and display their property values in the Property
Grid.

Can someone please show me a C# example on how to do this.

Thank you.

Regards
Mark

Sep 18 '06 #2
Thanks Dave. I'll have a look at the links you sent.

Regards
Mark

"Dave Sexton" wrote:
Hi Mark,

The difference between the ToolBars functionality and your UserControl is that you are explicitly adding the ToolBar buttons at
design-time, but when you include your UserControl its Panel and Buttons are already there. This means that your nested Controls
are not being managed by the designer.

A UserControl is meant to be an encapsulated, composite control. In other words, it contains controls and makes them appear and
function as a single control in the designer.

One option would be to define public properties for each of the controls that you want publicly configurable at design-time:

[Category("Appearance"), TypeConverter(typeof(ExpandableObjectConverter))]
public Button Button1
{
get { return button1; }
}

With the above code button1 will be configurable via the PropertyGrid at design-time through the Button1 property. This does,
however, defeat the purpose of a UserControl to an extent.

You might want to look in to creating a custom designer for your control, but I'm not sure if you'll be able to accomplish your goal
that way:

IDesigner on MSDN:
http://msdn2.microsoft.com/en-us/lib...idesigner.aspx

DesignerAttribute on MSDN:
http://msdn2.microsoft.com/en-us/lib...attribute.aspx

--
Dave Sexton

"Mark Collard" <Ma*********@discussions.microsoft.comwrote in message news:C6**********************************@microsof t.com...
The ToolBar control allows you to add toolbar buttons. When you add a button,
the button is not only displayed in the toolbar, but also added as a
separator control in the form/usercontrol your toolbar exists in.

I'm writing my own usercontrol which contains various different controls
(e.g. Panel, Button). I would like these controls to be listed in the drop
down just above the Properties grid, when a new instance of the usercontrol
is added to the form. This will allow the user to select the controls and
customize them.

I also want to allow the user to able to click on the controls in the
usercontrol to select them and display their property values in the Property
Grid.

Can someone please show me a C# example on how to do this.

Thank you.

Regards
Mark


Sep 19 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Sebastian Hiller | last post: by
12 posts views Thread by Joe | last post: by
reply views Thread by oliver | last post: by
1 post views Thread by Giovanni | last post: by
1 post views Thread by RvGrah | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.