EDITED FOR BETTER UNDERSTANDING
I made a custom control with propertise for some global variables.
private string[] LBTitles = new string[1] { "Rien" };
//...
[CategoryAttribute("WildData"), DescriptionAttribute("Tableau des noms des titres au dessus de le listbox")]
public string[] Titles
{
get { return LBTitles; }
set { LBTitles = value; OnColumns(EventArgs.Empty); }
}
OnColums does many things to format the control. One among others is:
int vLongest = 0;
//...
//Si le plus long est plus petit que le titre de la colonne
if (vLongest < LBTitles[i].Length)
{
vLongest = LBTitles[i].Length;
}
The above is for my control itself. Everything work fine, its a wonderful day, etc.
Now when it comes to add it to a form: - I add it, everything is ok - I modify the properties via the design, everything is ok - I try to run it... there is the problem.
When I build, it add into InitializeComponent() the following code:
this.wildList1 = new WildList.WildList();
//Which is ok but also it add, everytime I build, this:
//
// wildList1
//
this.wildList1.Colors = new string[] {
null};
this.wildList1.Font = new System.Drawing.Font("Courier New", 8F);
this.wildList1.Location = new System.Drawing.Point(211, 33);
this.wildList1.Name = "wildList1";
this.wildList1.Positions = new int[] {
0};
this.wildList1.Size = new System.Drawing.Size(238, 224);
this.wildList1.TabIndex = 16;
this.wildList1.Titles = new string[] {
null};
It add lines of code that reset my arrays. Why? How can I get ride of them? Or at least, make them use the values entered by the programmer (aka me) into the designer?
Because when it goes throu the line that reset it, it also call the property "set", which call OnColumns, which then try to do stuff with empty arrays, which cause a crash.