I have 10 buttons and a textbox on my widow form.
11th button to fire the operation.
Task is that i need to input a no. in the textbox ranging from 1-10,
and press the fire button.
This should change the forecolor of the respective button in the form.
Suppose i enter 5 and press fire.
This should change the forecolor of the button5.
i.e button5.forecolor=....

I am already addressing the issue by using if statements like.
if textbox1.text == 1
button1.forecolor = red;
if textbox2.text == 2
button2.forecolor = red;

But this is hectic incase i have around 20 buttons.
So how to access the control button and its properties by specifying its id at the runtime??

Recommended Answers

All 2 Replies

Put the button in to an array and use the value from the TextBox as an index in to the array (-1 of course).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.