I've made a small Knight's Tour program, and am trying to tighten up the code with a loop instead of doing something one by one, like I had it the first time.
There's a panel containing 25 buttons which represent the board. There is a "solve" button is for displaying a little animation showing the user how to solve the puzzle. The buttons on the board are named Button1 through Button25, all placed in order. This is the code I inserted to test my new method, but it didn't give the results that I expected.
It filled in the buttons with a pause in between, like I wanted, but it did it in a seemingly random order (Button18, then 25, then 24, then 10, etc). I had guessed that it would do it in order of name, or tab index, but it doesn't. I can move the buttons around on the form and have it animate the way I wanted, but I'd like to figure this out instead.
How is this order determined?
There's a panel containing 25 buttons which represent the board. There is a "solve" button is for displaying a little animation showing the user how to solve the puzzle. The buttons on the board are named Button1 through Button25, all placed in order. This is the code I inserted to test my new method, but it didn't give the results that I expected.
Private Sub btnSolve_Click(sender As Object, e As EventArgs) Handles btnSolve.Click resetboard() solve() End Sub Sub solve() For Each button In Panel1.Controls button.BackColor = Color.Black System.Threading.Thread.Sleep(500) Refresh() Next End Sub
It filled in the buttons with a pause in between, like I wanted, but it did it in a seemingly random order (Button18, then 25, then 24, then 10, etc). I had guessed that it would do it in order of name, or tab index, but it doesn't. I can move the buttons around on the form and have it animate the way I wanted, but I'd like to figure this out instead.
How is this order determined?