How to get reference to object (button) by name

I have a graphics program that uses a list<string> to store component names for the various scenes.
When I want put a new graphic up I check an XML file to see if any current scenes that are currently being displayed need to be removed. This works fine but when the other scenes are put up a (derived) button is set to a particular state.

When I remove the scene I need to be able to also reset the button state.

The best way would be to store the button's name in the XML file and use a call to get a reference to the object so I can use this to reset it.

Failing this I could create a function to reset the button state so would like to get a reference to this function from the name stored in the XML file.

Does anyone know the call to get the object reference or failing that the function reference from a string (name)
LVL 1
jetbetAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Assuming WinForms?  You can search for the Control using Controls.Find():
        private void button1_Click_1(object sender, EventArgs e)
        {
            string ctlName = "button2";
            Control[] matches = this.Controls.Find(ctlName, true);
            if (matches.Length > 0 && matches[0] is Button)
            {
                Button btn = (Button)matches[0];
                btn.Text = "Hello!";
            }
        }

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jetbetAuthor Commented:
Thanks for that. This will get me going in the right direction.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.