Turkalp Kucur

Turkalp Kucur

  • NA
  • 50
  • 19k

controlling another button in runtime....

Oct 21 2012 5:35 AM


Hello there...

I have created two buttons with runtime control:





 

private void Form1_Load(object sender, EventArgs e)
        {
           for(int i=0;i<2;i++)
           {
            Button btn = new Button();
            btn.Size = new Size(80, 80);
            btn.Name = "deneme" + i;

            btn.Left = 80;
            btn.Top = i * 90;
              
            this.Controls.Add(btn);
            btn.Click += new EventHandler(btn_Click);
            
           }
        }
        void btn_Click(object sender, EventArgs e)
        {
            Button gonderen = (Button)sender;
            gonderen.BackColor = Color.Blue;
        }private void Form1_Load(object sender, EventArgs e)
        {
           for(int i=0;i<2;i++)
           {
            Button btn = new Button();
            btn.Size = new Size(80, 80);
            btn.Name = "deneme" + i;

            btn.Left = 80;
            btn.Top = i * 90;
              
            this.Controls.Add(btn);
            btn.Click += new EventHandler(btn_Click);
            
           }
        }
        void btn_Click(object sender, EventArgs e)
        {
            Button gonderen = (Button)sender;
            gonderen.BackColor = Color.Blue;
        }


There are two buttons created in the form...



When I click one of the button, its color turns to blue...



My aim is, when I click one of the button, I want to change the color of the other button.

How could I accomplish that....


Answers (2)