This is the problem:
I add a lot of buttons, pictureboxes, textboxes and other controls like this:
btnStart = new Button(); bla bla bla text text text…
And I have been adding more. So, I have learned that I can remove them one by one:
Controls.Remove(btnStart);
But what I do want to know is, if there is a way to remove all of them at once, not specifying every single one of them when I want to remove them. Basically I want to create new:
private void ClrScr() { //Help??? }
Which will remove all controls once called from this form (Everything is done in one form).
Can anyone help out? I’m still quite new at this.
Controls.Clear( )should do it.Edit:
As pointed out below –
Controls.Clear( )can result in memory leaks. Have a look at this answer: How to Clear() controls without causing a memory leak