C# User control containing child -


i created user control inherits panel. goal have collection of collapsible panels.

here how user control looks (no comment on ugly it's :p) i'm using main class control, 1 collection (using collectionbase) , 3rd one, item.

my problem when add item, need main control added panel. drawing looks fine, i'm not getting expected result.

i'm not sure expose problem. let's in visual studio putting panel1 on form1, , panel2 + panel 3 in panel 1

the form1.designer.cs contain :

    form1.controls.add(panel1);     panel1.controls.add(panel2);      panel1.controls.add(panel3); 

this i'll willing do. tried create event onitemadded , subscribe in order add panel not working charm, plus trigger @ compilation, each time collection getting populated while needs done once only.

i'm sorry bad english, if need clarify something, not hesitate tell me. i'm not sure part of code need, if want, ask !

thank you hints in advance !

hi terrybozzio , thank answering.

here important parts of code. first class, main

    [designer(typeof(collapsiblepaneldesigner))]     [designer("system.windows.forms.design.parentcontroldesigner, system.design", typeof(idesigner))]      public partial class collapsiblepanel : panel     {         private collapsiblepanelitemcollection _items = null;          [browsable(true)]         [editor(typeof(collapsiblepanelitemcollectioneditor), typeof(uitypeeditor))]         [designerserializationvisibility(designerserializationvisibility.content)]          public collapsiblepanelitemcollection items         {             { return _items; }         }          public collapsiblepanel()         {             initializecomponent();             setstyle(controlstyles.allpaintinginwmpaint | controlstyles.userpaint controlstyles.optimizeddoublebuffer, true);             _items = new collapsiblepanelitemcollection(this);         } 

}

the second class, inherits collectionbase follow :

    public class collapsiblepanelitemcollection : collectionbase     {         private collapsiblepanel _owner = null;          public int indexof(collapsiblepanelitem item)         {             return innerlist.indexof(item);         }          public collapsiblepanelitem this[int index]         {             { return (collapsiblepanelitem)innerlist[index]; }         }          public collapsiblepanelitemcollection(collapsiblepanel owner)         {             _owner = owner;         }          public void add(collapsiblepanelitem item) { }          public bool remove(collapsiblepanelitem item) { } 

}

    public class collapsiblepanelitemcollectioneditor : collectioneditor     {          private type[] _types;          public collapsiblepanelitemcollectioneditor(type type) : base(type)         {             _types = new type[] { typeof(collapsiblepanelitem) };         }          protected override type[] createnewitemtypes()         {             return _types;         }     } 

the third class, item of collection :

    [defaultproperty("text")]     [typeconverter(typeof(collapsiblepanelitemconverter))]     public class collapsiblepanelitem     {         private bool _iscollapsed = false;         private string _text = "text";          private int _index = -1;         private panel _panel = new panel();          // simplified properties of course         [defaultvalue(false)]         public bool iscollapsed { { ; set; } }          [defaultvalue(typeof(string), "text")]         public string text { { ; set; } }          [browsable(false)]         public int index { { ; set; } }          public panel panel { { ; set; } }          public collapsiblepanelitem() { }          public collapsiblepanelitem(string text, int containersize, image image, bool iscollapsed)         {             _text = text;             _containerheight = containerheight;             _headerimage = image;             _iscollapsed = iscollapsed;         }     }      public class collapsiblepanelitemconverter : expandableobjectconverter     {          public override bool canconvertto(itypedescriptorcontext context, type destinationtype)         {             return (destinationtype == typeof(instancedescriptor)) ? true : base.canconvertto(context, destinationtype);         }          public override object convertto(itypedescriptorcontext context, cultureinfo culture, object value, type destinationtype)         {             if (destinationtype == typeof(instancedescriptor))             {                 if (value collapsiblepanelitem)                 {                     collapsiblepanelitem objvalue = (collapsiblepanelitem)value;                     type[] types = new type[3];                     object[] values = new object[3];                     types[0] = typeof(panel);                     values[0] = objvalue.panel;                     types[1] = typeof(string);                     values[1] = objvalue.text;                     types[2] = typeof(int);                     values[2] = objvalue.index;                     return new instancedescriptor(typeof(collapsiblepanelitem).getconstructor(types), values, true);                 }             }              return base.convertto(context, culture, value, destinationtype);         }     } 

of course, when read collapsiblepanelitem class, you'll understand dont know i'm doing panel... ;)


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

html - Repeat image to extend header to fill screen -

javascript - Backbone.js getting target attribute -