Hola gente que tal. Necesitaba hacer un array de botones en c# e hice lo siguiente:
Form1.Designer.cs
Código:
namespace Plataforma
{
partial class Form1
{
/// <summary>
/// Variable del diseñador requerida.
/// </summary>
private System.ComponentModel.IContainer components = null;
private System.Windows.Forms.Button[,] buttons;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.buttons = new System.Windows.Forms.Button[7,7];
this.SuspendLayout();
//
// buttons
//
int x = 0;
int y = 0;
for (int i = 0; i < 7; i++)
{
x = 0;
y += 50;
for (int j = 0; j < 7; j++)
{
x += 50;
this.buttons[i,j] = new System.Windows.Forms.Button();
this.buttons[i,j].Location = new System.Drawing.Point(x, y);
this.buttons[i,j].Name = "button1";
this.buttons[i,j].Size = new System.Drawing.Size(50, 50);
this.buttons[i,j].TabIndex = 0;
this.buttons[i,j].Text = "button1";
this.buttons[i,j].UseVisualStyleBackColor = true;
this.Controls.Add(this.buttons[i,j]);
}
}
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(479, 356);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
}
}
Cuando compilo me funciona de 10. Me muesta todos los botones en sus lugares perfectamente. Pero cuando entro al modo diseño (Form1.cs) me dice:
Código:
El diseñador no puede procesar el código en la línea 22:
this.buttons = new System.Windows.Forms.Button[7,7];
El código del método 'InitializeComponent' se genera mediante el diseñador y no se debe modificar manualmente. Quite cualquier cambio realizado e intente abrir el diseñador de nuevo.
Igualmente funciona, pero no puedo acceder al modo diseño. Alguna solución?
Muchas gracias.
PD: PERDONEN PERO ME OLVIDÉ DE PONER EL TEMA EN NEGRITA.