I’ve started making a Minesweeper game in vb.net using a dynamically created grid of buttons, which are stored in a 2D array. I have another 2D array (Boolean), that keeps track of whether a certain position is covered or uncovered. And I have an ‘update grid’ method that can be ran whenever, to update the grid, so that all that should be uncovered is uncovered on the screen.
How would I make it so that when any button is clicked, that button’s state is set to uncovered? I tried using an event handler, but I couldn’t pass any arguments, and I need to know the button’s x and y position, so I can uncover the correct button.
Thanks.
You could put all your buttons in a
Dictionary(Of Button, Boolean)each with the valueTrue. Later in your Click event handler cast the sender to Button and set the corresponding entry in the dictionary toFalse.Somewhat like this (excuse my bad VB, I’m normally using C#):
Update: Alternatively — as @Hans Passant pointed out in the comments to your question — you can use the
Tagproperty, which would be simpler.