No, there is no automatic way to do this: you have to store the information on what controls you added where in nonvolatile storage (ie, on disk) either with the Application settings file, or via a file of your own devising. Then reload the infor and re-add the controls next time you open the form.
"I'm not sure I know what you mean
I know how to use for each loop I think
like this?
For Each ctrl In FlowLayoutPanel1.Controls
If TypeOf ctrl Is TextBox Then
If ctrl.Name = ask Then
ctrl.Dispose()
End If
End If
Next ctrl
I don't really understand how to write that code"
Yep - that's a For Each loop and I'll just digress into them a bit.
For Each is one of the simplest kinds of loop - it works with (almost) every collection from Arrays to Lists, and so on (basically anything which is in the IEnumerable "club" can go in a For Each loop, but don;t worry about that just yet)
What is does is takes each item in the collection in turn, and executes the code in the loop using that instance. It's like a pile of coins: if you want to know how many are Heads and how many are Tails, you take each one of the top of the pile in turn and look at it, write down the Head or Tail and move on to the next.
In your code the Collection is
FlowLayoutPanel1.Controls
and each Control is put into the
ctrl
variable in turn.
You can do this with strings as well:
Dim lines As String() = File.ReadAllLines("D:\Temp\myData.txt")
For Each line As String In lines
...
Next
So where you want to start is:
Dim lines As String() = File.ReadAllLines("D:\Temp\myData.txt")
For Each line As String In lines
Dim input As String = "label data|textbox data"
Dim parts As String() = input.Split("|"C)
Dim forTheLable As String = parts(0)
Dim forTheTextbox As String = parts(1)
...
Next
Then all you have to do is extract the code from your click event handler into here and you're done.
Does that make sense?