Hey,
Sorry for a possible dumb post, I dont post at all usually! I haven't coded for that long in c# so as i said this may be dumb quest.
I get the feeling that the designer does not like arrayed components as i have done:
Ctrl = new System.Windows.Forms.CheckBox[4];
for (int i = 0; i < 4; i++)
{
this.Ctrl= new System.Windows.Forms.CheckBox();
}
for (int i = 0; i < 4; i++)
{
this.Ctrl.Location = new System.Drawing.Point(16, 24 + (i * 32));
this.Ctrl.Name = "Ctrl" + Convert.ToString(i);
this.Ctrl.Size = new System.Drawing.Size(40, 16);
this.Ctrl.TabIndex = i + 1;
this.Ctrl.Text = Convert.ToString(i + 1);
this.Ctrl.CheckedChanged += new System.EventHandler(this.CheckChange);
}
This compiles fine but the designer does not like it. I dont exactly know what i'm asking (helpful i know) but i just dont understand why the designer is so picky with how things must be set.
I use the arrays so that less if statements are used in my main code:
for (int i = 0; i < 4; i++)
if ((Ctrl
{
PC
PCBits
}
etc...
I'm just wondering if this is just somthing i have to accept, or if i'm doing it a bad way, cause obviously poeple must used arrayed components! I hope you can see what i am trying to do.
btw the error says:
The code within the method 'InitializeComponent' is generated by the designer and should not be manually modified. Please remove any changes and try opening the designer again. G:\MIC & FER\Control\Form1.cs 111 0
All in all i think i'm just going overboard in trying to keep what i think is tidy code.
Any sort of feedback would be appreciated, thanks in adavance
Ad.
p.s. I couldnt see how to add code sample areas( ) so all my [ i ] are looking like bulbs, i appologise.

Designer doesn't like Array InitializeComponent code
Ashis Kumar Dutta
The problem is not so much what your code is doing as it is where you are putting it. As the error states, the code in InitializeComponent is automatically generated by the designer and you shouldn't modify it. If the designer ever needs to regenerate that code, you will likely lose your changes.
There's nothing wrong with your approach (tidy code being a good thing) but if you're going to use the Designer to create a form, you're going to have to let it manage the components.
-Tom Meschter
Software Dev, Visual C# IDE
Lance Hunt
Oh, and you can enclose code in between "[ code language="C#"]" and "[/code]" tags (just remove the space between "[" and "code" when you do). It will display like so:
for (int i = 0; i < 10; i++)
{
Console.WriteLine(i);
}
-Tom Meschter
Software Dev, Visual C# IDE