Start with the number zero, and each time an object is created, add one.
That's the logic.
If you mean something like creating a class, and counting how many times an object of that class is created, put the functionality to do the counting inside the constructor and make the counter shared across all instances (for example, by making it static).
Don't forget that you will need to add the counter increment to the copy constructor and the assignment operator. You probobly want to have that as a seperate counter since those objects will be implicitly created.
For Each ctrl As Control In Me.Controls("pnlMainPanel").Controls
If ctrl.GetType Is GetType(System.Windows.Forms.Panel) Then
For Each subCtrl As Control In ctrl.Controls
If subCtrl.GetType Is GetType(System.Windows.Forms.TextBox) Then
If subCtrl.GetType Is ...