how to change the property of particular control in array of control

Posted on 2006-06-05
Medium Priority
Last Modified: 2010-04-16
Hi Experts,

I have created on project in C#.
Which creates one or more runtime time button.i.e. array of button controls.
According to button pressed the property should be changed for that particular button.
and I want to create one event to handle this change.
I have subscribeed same event to all control buttons.
But unfortunately it affects on only one button not any other button.
means how to code for control array in event.

can you give me hint how to do this.

Thanks in advance.
Question by:avinash_takale
LVL 86

Accepted Solution

Mike Tomlinson earned 800 total points
ID: 16838215
Cast the sender parameter to a button...

Here is a simple example:

        private void button1_Click(object sender, EventArgs e)
            Button btn;
            for (int i = 0; i < 5; i++)
                btn = new Button();
                btn.Text = "Button" + i.ToString();
                btn.Location = new Point(i * btn.Width, 50);
                btn.Click += new EventHandler(btn_Click);

        void btn_Click(object sender, EventArgs e)
            Button btn = (Button)sender;
            btn.Text = "Clicked";
            btn.BackColor = Color.Red;

Author Comment

ID: 16838252
Thank a lots
I really appriciated.
Its working fine,  

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Screencast - Getting to Know the Pipeline
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question