You got to loop through the controls in your form and then when you find the right one you can remove it. (foreach control in this. Controls) You probably also need to redraw the parent form to get the change to display after you’ve removed the control. I usually set visibility to false instead of deleting. That way you can show the button or textbox again at a later time if you need that.
But the thing is the buttons are made with code inside an if statement and they also change based on other stuff
Well according to your code, you’re declaring Hexes as a new, empty list, and then trying to loop through that empty list, so your loops won’t even execute. Put a breakpoint inside your foreach loops, and you’ll see that they are never hit.
You should be looping through the controls of your form. I’m not sure what the purpose of declaring “Hexes” is?
Basically theres multiple buttons and each time the button is clicked it spawns buttons. But I want the old ones to dissappear and the new ones to replace them each time
C# devs
null reference exceptions