By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,889 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,889 IT Pros & Developers. It's quick & easy.

Advanced UserControl Question

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.