tags:

views:

89

answers:

3
int a, b;

    private void Form1_Load(object sender, EventArgs e)
    {
        this.Width = 600;
        this.Height = 436;

        for (a = 1; a <= 8; a++)
        {
            for (b = 1; b <= 8; b++)
            {
                Button btn = new Button();
                btn.Name = (((a - 1) * 8) + b).ToString();
                btn.Width = 50;
                btn.Height = 50;
                btn.Left = (b - 1) * 50;
                btn.Top = (a - 1) * 50;

                if ((a + b) % 2 == 0)
                    btn.BackColor = Color.WhiteSmoke;
                else
                    btn.BackColor = Color.Black;

                btn.Click += new EventHandler(btn_Click);

                this.Controls.Add(btn);
            }
        }
    }
    int i, j,y;
    void btn_Click(object sender, EventArgs e)
    {
        Button btn = (Button)sender;

        if (radioButton1.Checked == true)
        {
            i = int.Parse(btn.Name);
            j = i % 8;
            for (y = 1; y <= 8; j+=8)
            {

            }
        }

how can i change other buttons backcolor?

A: 

You'll need to keep a reference to the other buttons. Preferably: create all buttons, add them to a list. In the eventhandler, iterate that list and set the background color

Onkelborg
+1  A: 

Make a List<Button> and add your newly added buttons to this list. Then, you can change any property of button in this list with getting button's index

Serkan Hekimoglu
siz türksünüz galiba
evet Türküm :))
Serkan Hekimoglu
bende çeyrek ingilizcemle yarım yamalak bişey sormaya çalışıorum:)
profilimdeki mail adresimi kullanaraktan banada sorabilirsiniz :)
Serkan Hekimoglu
çok sağolun mailinizi kaydediyorum bu sorunu hallettim bi dahaki yanlışlarda size danışırım inşallah :)
tabii ki buyuk bir zevkle yardimci olurum
Serkan Hekimoglu
A: 

Use your this.Controls reference...not exactly syntactically correct....but you get the idea...

    Button btn = (Button)sender;

    if (radioButton1.Checked == true)
    {
        i = int.Parse(btn.Name);
        j = i % 8;
        for (y = 1; y <= 8; j+=8)
        {
           if(!btn.equals(this.Controls[y]))
              this.Controls[y].BackColor = Color.Red;
        }
    }
Aaron