You can see how much txtName.ActualHeight you get without a wrapper, and then divide ActualHeight (with a wrapper) by the value you received earlier. You should get the number of rows.
Note: you will not get the actual height in the constructor. You will receive it after the text block is displayed on the form.
for example: (Nowrap)
txt.ActualHeight 311.0
(hoop)
txt.ActualHeight 1420.4400000000019
So,
int lineCount = (txt.ActualHeight / 311.0)
Hope this helps :)
Update for your update:
If you need to set the height of the messages according to the height of your text block, you can simply do this:
msgbox.Height = txt.ActualHeight + 10;
// I added 10 just to add a little margin.
Avishek
source share