Problem with AddRange()

cyuksel

Newcomer
Joined
Mar 14, 2003
Messages
18
Location
turkey
Hi everybody,
i have a new problem.
I have a class called TypeContainer derived from usercontrol which is used as container for my other usercontrols,
i wrote a rootdesigner for TypeContainer class.

i have test project. there is a class derived from TypeContainer. My usercontrols can be draged from toolbox to design view and in the code part these usercontrols can be added as members. but I noticed that in initializecompoent method there is no "AddRange" statement for my usercontrols.

what i expect is the following:

this.Controls.AddRange( new TypeControl[]{typecontrol1,..})

so,when i close the file and reopen it,i can't see my usercontrols on design view, although their definitions are in code part.

Do you have any idea?

(I used ShapeLibrary sample as reference, AddRange method could be added in test class of ShapeLibrary.How?).

thanks for attention.


Here is my test class code:

C#:
public class Component1 : TypeContainer {
private TypeLibrary.TypeControl typeControl1;
private TypeLibrary.TypeControl typeControl2;
private System.ComponentModel.Container components = null;

public Component1(System.ComponentModel.IContainer container){
container.Add(this);
InitializeComponent();
}

public Component1()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.typeControl1 = new TypeLibrary.TypeControl();
this.typeControl2 = new TypeLibrary.TypeControl();
}
}
 
Last edited by a moderator:
Weird, it should do this automatically. I have a control out there that does this fine, if there are child controls of your control it should search them. The only thing I can think of is if UserControl were doing something funny with the Controls property, in which case deriving from ContainerControl instead would fix it. I don't think that can be the problem though.
 
Thanks Divil for attention.

i solved the problem. i should have written a collection class for my container class.After i implemented the collection class, now it is added automatically.


Can i ask a new question? My usercontrols have a designer derived form ControlDesigner class. When i add this usercontrol onto a windows form , it works fine. But when i add this usercontrol onto the document which has its own rootdesigner(i implemented), the control designer does not work.

DocumentDesigner class has a method CanBeParented(IDesigner parentdesigner) to indicate whether the control managed by the parameter designer can be a child of the control managed by document designer.

i attempted this method, the result did not changed.

i will be gratefull,if you can reply me.

thanks for everything.
 
I think CanBeParented returns whether or not the control being be that designer can be parented to the designer passed in as an argument. CanParent, on the other hand, returns whether the current designer can act as a parent to the control passed as an argument. Confusing stuff.

Since DocumentDesigner inherits from ParentControlDesigner I can't see why it would behave differently and not initialize your designers. Have you tried debugging outputs to see if the Initialize() or even the constructor is ever being called on your designers?
 
i tried to debug by using messagebox in initialize() and constructor of the designer but none of them returns a message.

i think, it means my designer does not initialized by my rootdesigner.

i examined the ShapeLibrary sample, and i saw that they implements designers as same way as i do. but their designers works . i don't know what is my mistake?

thanks
 
The designer isn't instantiated by the root designer, it's instantiated by the Visual Studio environment itself, where it's hosting the container bound to IDesignerHost. Is the problem that your root designer is allowing you to draw your controls on the form but they are appearing in runtime mode, without their designers?
 
My rootdesigner allow me to draw my controls on my document at design time .

My problem is that when I check their properties in the property browser I can't find my added properties.(neither verbs nor postfilterproperties(),prefilterproperties() methods do their work.)
 
Back
Top