Custom UserControl with subcontrols (designer support)

M

Martin Schulze

Hello,

i tried to compose myself a custom usercontrol which is derieved from
System.Windows.Forms.UserControl.

It contains 2 comboboxes and one textbox (which are also custom
controls,
but directly derived from the .net classes ComboBox and TextBox)

I did the custom control in the visual studio .net designer in which i
aligned the
controls inside properly, set the anchors and the other layout things.

As i compiled it and dropped in onto a new form i cannot select any of
the components (i.e. the comboboxes) inside the control.

I wanted to use the control in such a way that i can select the
subcontrols inside the control and adjust the settings for each one
individually in the propertygrid.

How can i do this?

I tried to overwrite the Control.Controls Method but that did not
work.
And i read its not that easy because one overwrites the serializer and
that must be handled properly.

(i know that has something to do with design-time support, but i dont
understand it properly)

but with the control-subcontrol property i should not go into deph
with design time programming.
or am i wrong?

could anyone tell me what to do to make the subcontrols available in
the designer (i.e. which methods to overwrite ?)

and where can i find resources or books about design time programming
besides the msdn-documentation?

thanks

Martin
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hello Martin,

The contained controls are declared private in the user control code by
default. This effectively prevents them to be modified when your user
control is placed onto a form in the designer. You should declare them as
public if you want the control's clients to be able to modify their
properties.

To do that, open your user control in the designer, select all the controls
and change their Modifiers property value to "Public" in the Property
Browser.
 
M

Martin Schulze

Hello Martin,
The contained controls are declared private in the user control code by
default. This effectively prevents them to be modified when your user
control is placed onto a form in the designer. You should declare them as
public if you want the control's clients to be able to modify their
properties.

To do that, open your user control in the designer, select all the controls
and change their Modifiers property value to "Public" in the Property
Browser.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Hello,

i did that but that had no effect in the designer window.

i wanted to click onto the subcontrol in the control and modify its
properties.

but meanwhile i found a solution in an example found in the internet.
It has a control collection and is done by a custom designer and a
custom type-converter.

thanks a lot
Martin
 
G

Guest

I have a similar problem - UserControl composite control, one of sub controls is a listView. I had delegated Columns property of my composite control to the listView's Column property hoping that the designer would be able to add/configure column headers for my listView. It kind of works but the designer obviously does not know that it needs to generate code to add column headers to my list view. The code that usually looks like this:

lView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2, this.columnHeader3});

is missing.

Does the example you found on the net cover designer support for user controls (especially code generation aspects)? I would appreciate URL or any clues on the subject
Regards
bk


----- Martin Schulze wrote: -----
Hello Martin,
The contained controls are declared private in the user control code by
default. This effectively prevents them to be modified when your user
control is placed onto a form in the designer. You should declare them as
public if you want the control's clients to be able to modify their
properties.
To do that, open your user control in the designer, select all the controls
and change their Modifiers property value to "Public" in the Property
Browser.
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Hello,

i did that but that had no effect in the designer window.

i wanted to click onto the subcontrol in the control and modify its
properties.

but meanwhile i found a solution in an example found in the internet.
It has a control collection and is done by a custom designer and a
custom type-converter.

thanks a lot
Martin
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi,

You should specify the same UIEditor for the property you use to expose the
columns collection as is used for the original Columns property. Still, I am
not sure code generation will work seamlessly - I am just not that
experienced in advanced design-time support for UI controls.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

BorisDotNet said:
I have a similar problem - UserControl composite control, one of sub
controls is a listView. I had delegated Columns property of my composite
control to the listView's Column property hoping that the designer would be
able to add/configure column headers for my listView. It kind of works but
the designer obviously does not know that it needs to generate code to add
column headers to my list view. The code that usually looks like this:
lView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2, this.columnHeader3});

is missing.

Does the example you found on the net cover designer support for user
controls (especially code generation aspects)? I would appreciate URL or any
clues on the subject
Regards
bk


----- Martin Schulze wrote: -----
Hello Martin,
The contained controls are declared private in the user control
code by
default. This effectively prevents them to be modified when your user
control is placed onto a form in the designer. You should declare them as
public if you want the control's clients to be able to modify their
properties.
To do that, open your user control in the designer, select all the
controls
and change their Modifiers property value to "Public" in the Property
Browser.
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Hello,

i did that but that had no effect in the designer window.

i wanted to click onto the subcontrol in the control and modify its
properties.

but meanwhile i found a solution in an example found in the internet.
It has a control collection and is done by a custom designer and a
custom type-converter.

thanks a lot
Martin
 
G

Guest

Arrggg - Martin, I'm trying to do this also - where'd you find the aricle on the web
Could you post it here please
This is making me crazy, it should be far, far simpler than this... :

----- Martin Schulze wrote: ----
Hello Martin
The contained controls are declared private in the user control code b
default. This effectively prevents them to be modified when your use
control is placed onto a form in the designer. You should declare them a
public if you want the control's clients to be able to modify thei
properties
To do that, open your user control in the designer, select all the control
and change their Modifiers property value to "Public" in the Propert
Browser
Dmitriy Lapshin [C# / .NET MVP
X-Unity Test Studi
http://www.x-unity.net/teststudio.asp
Bring the power of unit testing to VS .NET ID

Hello

i did that but that had no effect in the designer window

i wanted to click onto the subcontrol in the control and modify it
properties

but meanwhile i found a solution in an example found in the internet
It has a control collection and is done by a custom designer and
custom type-converter

thanks a lot
Marti
 
G

Guest

I'm not too sure about that. Default UIEditor for the collections is the Collection Editor. This editor is used for ListView and this is the editor I’m happy with. More to it, this editor is invoked by the designer, i can add/remove/modify column headers no problems, the code is generated to declare and to instantiate collection items but the code to add them to the collection is not there.
 
G

Guest

I found the answer. All I had to do was to adorn my Columns property (the one of the collection type) with appropriate Property Browser attribute

DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content

public ListView.ColumnHeaderCollection Column

ge

..



This attribute causes the Designer to serialize (generate) code to add collection items to the collection.
Fortunately for me the collection items are of known type (ListView ColumnHeaders) so I did not have to write Type Converter, UI Editor, etc

The answer was found in Chris Sells Windows Form Programming in C# that now worth it's weight in gold for me
Thanks Chris
 

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