If you want to calculate the height by going down the tree you don't need all that code. Just follow nodes down until you reach the end and thats your height. But the better thing to do is to keep track of the number of nodes in the data structure an just return ceil(log2(n)). Your code look to be running in O(n), I would do it like this...
But of course you can be off by 1 if you use this method, it depends on what the heigh value is going to be used for. If your looking for the most "correct" solution you probably want to go through the entire tree. I'm not sure if your code will work though, it not even returning anything.
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 ...