Lisans
03/02/2007, 14:55
Selam arkadaşlar. Hoca bir ödev verdi ödevde hafızada 10 adet buton ve textbox yaratılacak bunlar forma aktarılacak buraya kadar normal herşey ondan sonra butonun yanındaki textboxa örneğin en üstteki buton 1 en sondaki buton 10 numara olsun. 1 numaralı butonun yanındaki texte 5 yazdım o butona tıkladım 5 numaralı butona kadar 1 den başlayıp sıraya kırmızı olacak butonlar yani 2 numaralı buton kırmızı olcak sonra eski haline döncek 3 numaralı buton kırmızı olcak 5. buton kırmızı olduktan sonra durcak. Ben şöyle birşey yaptım ama olmuyor :D birde butona tıklayınca butonları ve textboxları forma atıcaz.
Color ilk;
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
{
Button btn = new Button();
btn.Left = 30;
btn.Top = 50 + (i * btn.Height);
btn.Text = i.ToString();
btn.Name = i.ToString();
ilk = btn.BackColor;
this.Controls.Add(btn);
TextBox txt = new TextBox();
txt.Left = 40 + btn.Width;
txt.Top = 50 + (i * btn.Height);
this.Controls.Add(txt);
btn.Tag = txt;
btn.Click += new EventHandler(btn_Click);
}
}
string sayi;
void btn_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
TextBox txt = (TextBox)btn.Tag;
if (txt.Text != "")
{
sayi = txt.Text;
if (int.Parse(sayi) > Convert.ToInt32(btn.Name))
{
timer1.Start();
}
else
{
}
}
else
{
MessageBox.Show("Lütfen boş geçmeyelim..");
}
}
int s = 0;
private void timer1_Tick(object sender, EventArgs e)
{
foreach (Control btn in this.Controls)
{
btn.Name = (0).ToString();
while (s != int.Parse(sayi))
{
if (Convert.ToInt32(btn.Name) == s)
{
if (btn is Button)
{
btn.Dispose();
this.Controls[s].BackColor = Color.Red;
}
else
{
}
}
else
{
this.Controls[s - 1].BackColor = ilk;
}
s++;
btn.Name = Convert.ToString(Convert.ToInt32(btn.Name) + 1);
}
}
}
Color ilk;
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
{
Button btn = new Button();
btn.Left = 30;
btn.Top = 50 + (i * btn.Height);
btn.Text = i.ToString();
btn.Name = i.ToString();
ilk = btn.BackColor;
this.Controls.Add(btn);
TextBox txt = new TextBox();
txt.Left = 40 + btn.Width;
txt.Top = 50 + (i * btn.Height);
this.Controls.Add(txt);
btn.Tag = txt;
btn.Click += new EventHandler(btn_Click);
}
}
string sayi;
void btn_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
TextBox txt = (TextBox)btn.Tag;
if (txt.Text != "")
{
sayi = txt.Text;
if (int.Parse(sayi) > Convert.ToInt32(btn.Name))
{
timer1.Start();
}
else
{
}
}
else
{
MessageBox.Show("Lütfen boş geçmeyelim..");
}
}
int s = 0;
private void timer1_Tick(object sender, EventArgs e)
{
foreach (Control btn in this.Controls)
{
btn.Name = (0).ToString();
while (s != int.Parse(sayi))
{
if (Convert.ToInt32(btn.Name) == s)
{
if (btn is Button)
{
btn.Dispose();
this.Controls[s].BackColor = Color.Red;
}
else
{
}
}
else
{
this.Controls[s - 1].BackColor = ilk;
}
s++;
btn.Name = Convert.ToString(Convert.ToInt32(btn.Name) + 1);
}
}
}