Je débute en C# et j'ai des probleme...
J'essaye de crée un petit morpion mais pour l'instant je n'ai que crée la fenetre winforms avec des checkBox mais ce code génere une erreur :
using System;
using System.Windows.Forms;
using System.Drawing;
namespace DefaultNamespace
{
/// <summary>
/// Description of MainForm.
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
const int nb_CB = 9;
CheckBox[] box= new CheckBox[nb_CB];
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
initCB();
}
private void initCB()
{
for(int i=0 ; i<=9 ; i++)
{
this.box[i] = new CheckBox();
this.box[i].Name = i.ToString();
this.box[i].Size = new System.Drawing.Size(24,24);
this.box[i].Text = "";
this.box[i].Click += new EventHandler(checkBox_Click);
}
this.box[0].Location = new Point(10,10);
this.box[1].Location = new Point(10,35);
this.box[2].Location = new Point(10,60);
this.box[3].Location = new Point(35,10);
this.box[4].Location = new Point(35,35);
this.box[5].Location = new Point(35,60);
this.box[6].Location = new Point(60,10);
this.box[7].Location = new Point(60,35);
this.box[8].Location = new Point(60,60);
this.Controls.AddRange( box );
}
private void activerCheckBox()
{
for(int i=0; i<nb_CB; i++)
{
this.box[i].Enabled = true;
this.box[i].Checked = false;
}
}
private void checkBox_Click(object sender, EventArgs ea)
{
CheckBox cb = (CheckBox) sender;
}
[STAThread]
public static void Main(string[] args)
{
Application.Run(new MainForm());
}
#region Windows Forms Designer generated code
/// <summary>
/// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might
/// not be able to load this method if it was changed manually.
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(392, 316);
this.MaximizeBox = false;
this.Name = "MainForm";
this.Text = "morpion";
this.ResumeLayout(false);
}
#endregion
public void ButtonClick(object sender, System.EventArgs e)
{
activerCheckBox();
}
}
}
C'est quoi le problème?