Firstly, what is the value of
index1
? Why are you appearing to use it in conjuction with
i
to reference the same element of
bu1
? Are they in step?
Why are you using
can_Count
as your loop termination condition, but not checking that this is lower or equal to
bu1.Length
?
I am guessing that the error occurs on the line
bu1[index1] = new Button();
which would indicate the
index1
is already outside the bound of
bu1
.
Put a breakpoint on the line
bu1[index1] = new Button();
Then run your program. Work out in your head what the various variables values should be, then check them. If they are ok, single step through repeating the checks until you spot the error. If they aren't what you think they should be, find out why not!