473,395 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 2801
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Tinus | last post by:
Hello all, I've create a custom control (UserControl) and have a custom Item Collection. The control is a custom calendar which is draw using the Graphics Rectangle etc. functions. It is drawn...
0
by: Sebastian Hiller | last post by:
Hello, i'm new to .Net (i'm using VB as language and i'm working in the code-behind mode) and i can't solve the following problem: I have a WebForm and want to Add a UserControl...
1
by: Will Gillen | last post by:
I know this has probably been asked before, but I can't seem to find a solid answer in any of the archives. First, before my question, please forgive my limited knowledge of the event lifecycle...
41
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based...
12
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control...
0
by: oliver | last post by:
QUESTION: How to access an object embedded in a UserControl through Javascript file? Another way to ask this question: How to execute script from a UserControl, accessing other objects in that...
1
by: Giovanni | last post by:
Dear Friends/Gurus, I have exhausted myself and have yet no solution to the following: I have an ASP.NET 2.0 Survey type application. On a page, I have placed a GridView which is bound to an...
10
by: Benton | last post by:
Hi there, I have a UserControl with a couple of textboxes and a couple of buttons ("Save" and "Cancel"). The Click event for this buttons is in the UserControl's codebehind of course, so here's...
1
by: RvGrah | last post by:
I have a usercontrol written in C# that exposes a public property of type double. This control is used in a program written in VB.net. If I set the value to 66.6667, it stays fine, I can break...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.