The Woo The Woo - 29 days ago 10
C# Question

How do I create a C# Array of Buttons?

How do I build an array of buttons in a Winforms application?

What I am trying to do is this: I have a lot of buttons in a sort of calendar arrangement, that are indicating time slots. IE: Monday0700Button, Monday0730Button, Monday0800Button, and so on in 30min intervals.

I have a xml database, where one of the fields for appointments is

<Duration>
When the duration = 0.5hrs, and the
<Time>
field equals "07:00am", to color the 'Monday0700Button'. When the Duration is 1.0hrs, I want it to populate 'Monday0700Button' as well as the following time slot button of 'Monday0730Button'.

Any ideas?
Thanks.

Answer

Yes, you can build a list of buttons like below.

List<Button> listOfButtons = new List<Button>();
listOfButtons.Add(yourButton);