Problemi vettori VC++

venerdì 07 maggio 2010 - 16.57

Fafa Profilo | Newbie

Salve a tutti, ho un problema in questa stinga di codice """letteraDaSpostare = Convert.ToChar(tb[i].Text);""",perche l'errore mi dice che // Riferimento a un oggetto non impostato su un'istanza di oggetto// vi metto il codice.

public partial class Form1 : Form
{
char letteraDaSpostare;
int i;
Random rnd = new Random();
Label[,] l = new Label[17, 17];
TextBox[] tb = new TextBox[8];
bool casellaCliccata = false;


public Form1()
{
InitializeComponent();
}


private void label_Click(object sender, EventArgs e)
{
Label labCliccata;
int riga, colonna;

labCliccata = (Label)sender;
riga = (labCliccata.Location.Y - 50) / 30;
colonna = (labCliccata.Location.X - 50) / 30;
txtprova.Text = " riga= " + riga + " col=" + colonna;
}
private void label1_Click(object sender, EventArgs e)
{
Label labCliccata;
labCliccata = (Label)sender;
txtprova.Text = " x= " + (labCliccata.Location.X - 50) / 30 + " y=" + (labCliccata.Location.Y - 50) / 30;
}
private void tb_MouseDown(object sender, MouseEventArgs e)
{
letteraDaSpostare = Convert.ToChar(tb[i].Text); <<<<--------------------ERRORE---------------------------------------------|
casellaCliccata = true;
}

private void tb_MouseLeave(object sender, EventArgs e)
{
if (casellaCliccata)
{
tb[i].Text = "";
}


}

private void label_MouseUp(object sender, MouseEventArgs e)
{
Label labCliccata;
int riga, colonna;

if (casellaCliccata)
{
labCliccata = (Label)sender;
riga = (labCliccata.Location.Y - 50) / 30;
colonna = (labCliccata.Location.X - 50) / 30;
l[colonna, riga].Text = Convert.ToString(letteraDaSpostare);
casellaCliccata = false;
}


}

private void btnAvviaPartita_Click(object sender, EventArgs e)
{

int ncelle = 17;
int i, j;
for (i = 0; i < ncelle; i++)
for (j = 0; j < ncelle; j++)
{
l[i, j] = new Label();
l[i, j].BackColor = System.Drawing.SystemColors.ActiveBorder;
l[i, j].BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
l[i, j].AutoSize = false;
l[i, j].Location = new System.Drawing.Point(50 + 30 * i, 50 + 30 * j);
l[i, j].Size = new System.Drawing.Size(30, 30);
l[i, j].Text = "";
l[i, j].Click += new System.EventHandler(this.label_Click);
l[i, j].MouseUp += new System.Windows.Forms.MouseEventHandler(this.label_MouseUp);
this.Controls.Add(l[i, j]);

}
l[8, 8].BackColor = Color.Red;
btnGeneraParole.Enabled = true;
for (i = 0; i < 7; i++)
{
tb[i] = new TextBox();
tb[i].Text = "";
tb[i].MouseDown += new System.Windows.Forms.MouseEventHandler(tb_MouseDown);
tb[i].MouseLeave += new System.EventHandler(tb_MouseLeave); //this.button4.MouseLeave += new System.EventHandler(this.button4_MouseLeave);
tb[i].Size = new System.Drawing.Size(30, 30);
tb[i].AutoSize = false;
tb[i].BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
tb[i].Location = new System.Drawing.Point(610 + 30 * i, 180);
this.Controls.Add(tb[i]);
}

}

private void btnGeneraParole_Click(object sender, EventArgs e)
{
int tmp;
for (i = 0; i < 7; i++)
{
tmp = rnd.Next(65, 90);

tb[i].Text = Convert.ToString(Convert.ToChar(rnd.Next(65, 90)));
}
}
}
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5